How do I split a string into a TStringList at the 2nd whitespace? (Solved) lazarus / 31-LCL ---------------------------------------------------------------------- funk247 · 2014-08-14 13:58 I'm trying to split a list of names into their component parts (i.e. fore & surname), normally I would do something like the following: Code: [Select]if name = '' then name := 'null' // Cater for empty strings         else           if (AnsiContainsStr(name , ' ') = True) then             begin             ExtractStrings([' '], [' '], PChar(name), result);             fore := result[0];             sur := result[1];             end However some of the data relates to business so ideally I need to split at the 2nd space char, does Lazarus have any inbuilt functionality that would allow me to do that? I've had a look at regexes but struggled to find a way to find the 2nd whitespace. In php it would be relatively simple, can I do anything like this? Code: [Select]$pos = strpos($info, '-', strpos($info, '-')); Some pointers in the right direction would be most welcome. ---------------------------------------------------------------------- typo · 2014-08-14 14:20 Code: [Select]  s := 'First Second Third';   ShowMessage(IntToStr(PosEx(' ',  s , Pos(' ', s) + 1)));  or, if the second space is also the last one: Code: [Select]  ShowMessage(IntToStr(RPos(' ', s))); ---------------------------------------------------------------------- funk247 · 2014-08-19 15:24 Quote from: typo on August 14, 2014, 04:20:38 pmCode: [Select]  s := 'First Second Third';   ShowMessage(IntToStr(PosEx(' ',  s , Pos(' ', s) + 1)));  or, if the second space is also the last one: Code: [Select]  ShowMessage(IntToStr(RPos(' ', s))); This was a really helpful post, heres my final code, works perfectly TVM! Code: [Select]with Initial_Data do begin     for i := 1 to RecordCount do begin         RecNo := i;         // Split Names         // Set name string         nm := Initial_Data.Fields[7].AsString;         // Capture position of split         if WordCount(nm, [' ']) > 2 then           posi := PosEx(' ',  nm, Pos(' ', nm) + 1)         else           posi := PosEx(' ', nm, 1);         // Set variables         fore := LeftStr(nm, posi);         surn := RightStr(nm, Length(nm) - Length(fore));         ... Add stuff to a dataset here ...     end; // End of Loop