[fpc-devel] String.Split inconsitent behaviour if Separators is [chars] vs [strings]

Bart bartjunk64 at gmail.com
Sat Sep 29 22:49:05 CEST 2018


Hi,

Consider this example:

program split;
{$mode objfpc}
{$h+}

uses
  sysutils;

var
  S: string;
  A: TStringArray;
  i: Integer;

begin
  S := '1 2 3 4 5';
  A := S.Split([#32],'"');
  writeln('S = ',S,', Separators = #32');
  for i := Low(A) to High(A) do writeln(format('%d: "%s"',[i,A[i]]));
  writeln;

  S := '1\n2\n3\n4\n5';
  A := S.Split(['\n'],'"');
  writeln('S = ',S,', Separators = \n');
  for i := Low(A) to High(A) do writeln(format('%d: "%s"',[i,A[i]]));
end.

Output:
S = 1 2 3 4 5, Separators = #32
0: "1"
1: "2"
2: "3"
3: "4"
4: "5"

S = 1\n2\n3\n4\n5, Separators = \n
0: "1"
1: "2"
2: "3"
3: "4"

I would expect the output would be the same for both versions of split?
The "string" version misses the last one?

-- 
Bart



More information about the fpc-devel mailing list