Discussion:
String.Split inconsitent behaviour if Separators is [chars] vs [strings]
(too old to reply)
Bart
2018-09-29 20:49:05 UTC
Permalink
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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://l
Sven Barth via fpc-devel
2018-09-29 21:21:54 UTC
Permalink
Post by Bart
Hi,
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.
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?
Please report as bug.

Regards,
Sven
Bart
2018-09-29 21:31:10 UTC
Permalink
On Sat, Sep 29, 2018 at 11:22 PM Sven Barth via fpc-devel
Post by Sven Barth via fpc-devel
Please report as bug.
Done: https://bugs.freepascal.org/view.php?id=34359
--
Bart
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/f
Michael Van Canneyt
2018-09-30 09:15:35 UTC
Permalink
Post by Bart
On Sat, Sep 29, 2018 at 11:22 PM Sven Barth via fpc-devel
Post by Sven Barth via fpc-devel
Please report as bug.
Done: https://bugs.freepascal.org/view.php?id=34359
Fixed. Thanks for reporting it.

Michael.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-b
Bart
2018-09-30 11:28:48 UTC
Permalink
On Sun, Sep 30, 2018 at 11:15 AM Michael Van Canneyt
Post by Michael Van Canneyt
Fixed. Thanks for reporting it.
Thanks for fixint it.
--
Bart
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-
Loading...