function GuessDecimalSeparator(const Value: string): Char;
var i,commacount,dotcount,lastsep:integer; c:char;
Const DefaultDecimalSeparator='.';
begin
commacount:=0;
dotcount:=0;
lastsep:=0;
for i:=1 to length(value) do
begin
c:=value[i];
if c = '.' then
begin
inc(dotcount);
lastsep:=i;
end;
if c = ',' then
begin
inc(commacount);
lastsep:=i;
end;
end;
Case (dotcount + commacount) of
0: result:=DefaultDecimalSeparator; //Default
1: Result:=Value[lastsep]; //accept the one separator
ELSE
//If a separator occurs more than once, it must be the thousand separator
Begin
if (commacount > dotcount) then result:='.' //multiple commas
else
if (dotcount > commacount) then result:=',' //multiple dots
else //equal amounts, take last separator
result:= Value[lastsep];
End;
end;
end;
This function uses the simple assumption that a decimal separator should occur at most one time in the string, but thousand separators may occur multiple times.