String.Split inconsitent behaviour if Separators is [chars] vs [strings]
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
If you use Array of String as separators as opposed to Array of Char, the result of String.Split differs.
In the case of strings, the last element is missing.
Steps to reproduce:
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"
Mantis conversion info:
- Mantis ID: 34359
- OS: Windows
- OS Build: 10
- Build: r39840
- Platform: i386
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 39843 (#a7278c18)
- Target version: 3.2.0