[fpc-pascal] Split and Join

Michael Van Canneyt michael at freepascal.org
Fri Nov 27 21:34:38 CET 2009



On Fri, 27 Nov 2009, Mattias Gaertner wrote:

> On Fri, 27 Nov 2009 20:11:25 +0100 (CET)
> Michael Van Canneyt <michael at freepascal.org> wrote:
>
>>
>>
>> On Fri, 27 Nov 2009, Juha Manninen wrote:
>>
>>> Hi,
>>>
>>> FPC's strutils or other libraries still don't have functions for splitting a
>>> string to a list and joining a list of strings again to one string, given a
>>> delimiter as a parameter.
>>> Something like:
>>>  function Spit(Str: string; Delim: string; Result: TStringList): integer;
>>> and
>>>  function Join(List: TStringList; Delim: string): string;
>>
>> Of course it does exist. Split can be implemented like this:
>>
>> List:=TStringList.Create;
>> List.Delimiter:=Delim;
>> List.StrictDelimiters:=True;
>> List.DelimitedText:=Str;
>>
>> And that's it.
>
> Many other languages can do that in one line with their RTL.
>
> Maybe as a special constructor.
>
> List:=TStringList.CreateFromSplit(SomeText,Delim);

That looks like a good suggestion, I'll add it as TStringList.CreateSplit.

Michael.



More information about the fpc-pascal mailing list