Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add more than 1 delimiter in TStringList

This is my delimited text: $HEHDT,10.17,T*28$HEHDT,10.18,T*2A and so on...

The comma is my sentence delimiter. However, I want to use the asterisk as my delimiter as well.

Output I want to achieve is:

$HEHDT 10.17 T 28 $HEHDT 10.18 T 2A

How do I specify more than 1 sentence delimiter in delphi? This is the code I have so far.

var
  MyStringList: TStringList;
  i: Integer;
begin
  MyStringList:= TStringList.Create;

  MyStringList.Delimiter := ','
  MyStringList.DelimitedText := '$HEHDT,10.17,T*28'+#13#10 +'$HEHDT,10.18,T*2A' +#13#10;

  for i= 0 to MyStringList.Count-1 do
    ShowMessage(MyStringList[i]);

  MyStringList.Free;
end;

For the above code, it only takes the comma as delimiter. How do I include 2 delimiters, both the comma and the asterisk?

Many thanks in advance! =)

like image 934
user1234637 Avatar asked Feb 27 '12 02:02

user1234637


1 Answers

Delphi stringlist is nice enough to give you the ability to parse text on one delimiter "for free". If you want a set of delimiters - then you need to use StrUtils.SplitString:

http://docwiki.embarcadero.com/VCL/en/StrUtils.SplitString

like image 106
paulsm4 Avatar answered Nov 19 '22 22:11

paulsm4