Explode in Delphi [duplicate]

2

I have a txt file where the data is saved as follows:

  

00: 46: 30 @ 21/08/2014 @ Carlos dos Santos @ São Paulo

In PHP I would use explode to transform each data before the "@" into columns.

How do I do this in delphi? I need to separate each data @ turn a column, so I can put them in a LISTVIEW.

    
asked by anonymous 29.08.2014 / 16:42

1 answer

5

A possible technical repair 1 is to use a TStringlist:

var
   Colunas : TStringlist;

begin
   Colunas := TStringlist.Create;
   Colunas.Text := StringReplace('00:46:30@21/08/2014@Carlos dos Santos@São Paulo',
      '@',Char(13)+Char(10),[rfReplaceAll]);

The TStringlist internally uses the CR LF sequence to separate the items, so the above code transforms a long line into several separate items, by changing the @ by the sequence CR LF

Edit : As well remembered by Edgar Muniz Berlinck , the TStringList has a property to break the string by other delimiters, thus:

var
   Colunas : TStringlist;

begin
   Colunas := TStringlist.Create;
   Colunas.Delimiter := '@';
   Colunas.DelimitedText := Linhas[i];

1. gambiarra

    
29.08.2014 / 16:46