Dear ALL,
Python csv module has a class with a handy method sniff() which allows to deduce the format of a CSV file, with an optional parameter containing possible valid delimiter characters.
It would be very useful to have a similar function in (Free) Pascal, which would return simply a char indicating the delimiter character:
function Sniff(sample: string; validchars: TSysCharSet = [',', ';', '|', #8]): char;
Such a function could be used as:
var
S: string;
begin
S := 'Col1; Col2; Col3';
WriteLn('Delimiter = "', Sniff(S), '"');
end.
which should return ";" in the above example.
Has someone implemented something like that? It should be simple enough, but I could not figure out how to implement it taking into account the possible existence of the delimiter character inside each data column, eg.:
S := '"Col 1, valid data", "Col2", "Col3"';
Any hints?
Best regards,