The current auto-generated code takes a lot of characters and feels a little bit counterintuitive in my opinion.
String.Split
is very powerful and needs way less code. And with ReadLn
there is no need for type conversion.
Examples:
program Example_1;
{$H+}
uses
SysUtils, Classes;
var
Input: String;
SplittedInput: Array of String;
Index: Int32;
begin
ReadLn(Input); // 123 321 456 654
SplittedInput := Input.Split(' ');
for Index := 0 to High(SplittedInput) do
begin
WriteLn(SplittedInput[Index]);
end;
end.
Output:
123
321
456
654
program Example_2;
{$H+}
uses
SysUtils, Classes;
var
Input: String;
SplittedInput: Array of String;
NumbersOfLines, Index: Int32;
begin
ReadLn(NumbersOfLines);
repeat
ReadLn(Input); // One; Two; Three; Test;
SplittedInput := Input.Split('; ', TStringSplitOptions.ExcludeEmpty);
for Index := 0 to High(SplittedInput) do
begin
WriteLn(SplittedInput[Index]);
end;
Dec(NumbersOfLines);
until NumbersOfLines = 0;
end.
Output:
One
Two
Three
Test
Links:
System.SysUtils.TStringHelper.Split
-
(https://www.freepascal.org/docs-html/rtl/sysutils/tstringsplitoptions.html)
-
(https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.split.html)
TStringSplitOptions