Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting TStringlist to string with delimiter

I have a list of strings stored in TStringList, i want to convert it into string seperated by commas and i use the following code

channelList: TStringList;
aCurrentChannel :=  Stringreplace(channelList.Text,Char(13)+Char(10),',',[rfReplaceAll]);

but the last character is coming as , like 1,2, is there anyway to avoid that?

like image 523
Jeeva Avatar asked Jul 16 '13 08:07

Jeeva


3 Answers

You need to use the DelimitedText property of the TStringList class. From the online help

Use DelimitedText to get or set all the strings in the TStrings object in a single string, separated by the character specified by the Delimiter property.

like image 56
RBA Avatar answered Oct 19 '22 09:10

RBA


use the DelimitedText property:

channelList.Delimiter := ',';
channelList.QuoteChar := ''; // or
channelList.QuoteChar := #0; // for higher delphi versions
aCurrentChannel := channelList.DelimitedText;
like image 37
whosrdaddy Avatar answered Oct 19 '22 11:10

whosrdaddy


While you're into string lists i suggest you to cast a look at http://wiki.delphi-jedi.org/wiki/JCL_Help:IJclStringList

// var channelList: iJclStringList;
var s: string;

s := JclStringList.Add(['aaa','bbb','ccc '])
         .Split('ddd: eee', ':', False).Trim.Join(',');
like image 1
Arioch 'The Avatar answered Oct 19 '22 09:10

Arioch 'The