Hi,
I'm returning to Lazarus after many years. Used to drive Pasal, TurboPascal, Delphi and Lazarus but the skills have faded.
Problem: need to split a string into words as in eg perl 'split'.
I've failed with SplitString, tried lots od magicspells and none worked.
I stole some online code which showed promise but I can't work out how to terminate the iteration.
The example below at least compiles ok but the 'MyLast' shows as -1, hoping for 3, possibly 4.
And the ugly repetition of the identifier 'MyList' seems to show that I'm missing a clue!
Help please? A fix to find the end of the list should be easy but I've spent hours chasing it. 'WordCount' didn't help, either.
A completely different solution would be very welcome.
Using Lazarus (how find verson, no Help|About?) and FPC 3.2.2 on Linux Mint 22.3, 64bit
program SplitProg.pas;
uses Classes, StrUtils;
var MyList : TStringList;
MyIndex, myLast : Integer;
MyDelim : Char = ',';
begin
MyList := TStringList.Create;
MyList.Delimiter := ',';
MyList.StrictDelimiter := True; // Ensures only ',' splits
MyList.DelimitedText := 'one,two,three,four';
// MyList[0] = 'one', MyList[1] = 'two', etc.
WriteLn ( 'MyLast := ', MyList.LastIndexOf(MyList.DelimitedText) );
//for MyIndex := 0 to myLast do
// Writeln (MyList[MyIndex]);
MyList.Free;
end.