Delphi: StringList Delimiter is always a space character even if Delimiter is set

Viewed 87989

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?

6 Answers
var
  MyString: String;
  Splitted: TArray<String>;

begin
  MyString := String.Join(',', ['String1', 'String2', 'String3']);
  Splitted := MyString.Split([','], 2);
end.

options:

Count : Maximum number of splits to return; defaults to MaxInt if not specified.

QuoteStart/QuoteEnd : Start and end characters of a quoted part of the string where the separator is ignored.

Options : Controls if any empty matches, or if trailing empty matches are included.

More info

Related