I am having trouble with the delimiter in the TStringList Class. Take a look:
var
s: string;
sl: TStringList;
begin
sl := TStringList.Create;
s := 'Users^foo bar^bar foo^foobar^barfoo';
sl.Delimiter := '^';
sl.DelimitedText := s;
ShowMessage(sl[1]);
end;
sl[1]
SHOULD return 'foo bar'
sl[1]
DOES return 'foo'
It seems that the delimiter is now '^'
AND ' '
Any ideas?
You should set s1.StrictDelimiter := True
for spaces not to be considered delimiters, more info here.
Since you work in a version that does not support the above (as was clarified after the answer was submitted), you have two options:
'hello hello^bye bye'
turns to '"hello hello"^"bye bye"'
. If you do choose this path and it works for you, please accept Alexander's answer and not mine, he also provides the code to implement it.Both workarounds not using StrictDelimiter
have limitations: the first requires some unused character, and the second requires no inverted commas and spaces in the original text.
Maybe it's time to upgrade to a newer version of Delphi :)