[fpc-devel] Is the code in wiki correct?

Amir amir at aavani.net
Mon May 11 07:51:31 CEST 2020


I assume StringJoin and StringSplit are one of the basic operations on 
Array of Strings and Strings. It looks like there is no easy way to use 
TStringList (that is claimed by the wiki to be a fancy "dynamic array or 
set of Strings"). These are not CSV-kind of functionalities...
  Are these functionalities implemented in rtl?



On 5/8/20 11:53 PM, Michael Van Canneyt wrote:
>
>
> On Fri, 8 May 2020, Amir wrote:
>
>> Hi there,
>>
>>   I was looking for a native implementation for JoinStrings and ended 
>> up in TStringList-TStrings_Tutorial 
>> <https://wiki.freepascal.org/TStringList-TStrings_Tutorial>.
>>
>>
>> <https://wiki.freepascal.org/TStringList-TStrings_Tutorial>
>> In Conversion to and from delimited strings 
>> <https://wiki.freepascal.org/TStringList-TStrings_Tutorial#Conversion_to_and_from_delimited_strings> 
>> section, it claims the following code works if the separator is a 
>> string:
>> MyStringList:= TStringList.create;
>> MyStringList.SkipLastLineBreak := True;
>> MyStringList.add('1');
>> MyStringList.add('2');
>> MyStringList.add('3');
>> result := StringReplace(MyStringList.Text,Lineending,'\n', 
>> [rfReplaceAll, rfIgnoreCase]);
>>
>> I believe this is not correct. What if there is a newline(LineEnding) 
>> in one of the strings?
>
> It will also be replaced. So yes, the code is wrong for such a case.
>
> TStringlist is not a silver bullet, and it is definitely not a 
> replacement
> for CSV-kind of functionality. If someone needs CSV, (s)he should use 
> the TCSVDocument class.
>
>
> Michael.
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20200510/e24317e1/attachment.htm>


More information about the fpc-devel mailing list