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

Sven Barth pascaldragon at googlemail.com
Sat Sep 29 23:21:54 CEST 2018


Bart <bartjunk64 at gmail.com> schrieb am Sa., 29. Sep. 2018, 22:50:

> 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?
>

Please report as bug.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180929/7f0ace52/attachment.html>


More information about the fpc-devel mailing list