I have this simple operation in Java, where the string is split by new line and break.
String i= "Holidays
Great.
Bye";
String []linesArray = i.split("\\r?\\n");
I would like to obtain the same result in Delphi 2006.
Is it valid to use the following steps?
charArray[0] := '\\r';
charArray[1] := '\\n';
strArray := strA.Split(charArray);
I interpret your request like this: "Split a string at both CR and LF." which implies that CR+LF gives an empty string element. For instance,
'alpha'#13'beta'#10'gamma'#13#10'delta'yields the five elements'alpha','beta','gamma','', and'delta'.If so, and if you are using a non-ancient version of Delphi, this is really simple:
For old Delphi versions
The code above requires
TStringHelper(crucially) and also makes use of inline variable declarations,for inloops, and generics.For old Delphi versions, you can do it manually: