4
I have the following function:
var
Colunas : TStringlist;
Item: TListItem;
begin
Colunas := TStringlist.Create;
Colunas.Text := StringReplace('00:46:30@21/08/2014@Carlos dos Santos@São Paulo',
'@',Char(13)+Char(10),[rfReplaceAll]);
Item := LV.Items.Add;
Item.SubItems.Add(Colunas[0]);
Item.SubItems.Add(Colunas[1]);
Item.SubItems.Add(Colunas[2]);
It separates by columns using the @delimiter, in this case I put manually. But, I have a file called client.txt and within it there are several lines of the type:
00:46:30@21/08/2014@Carlos dos Santos@são Paulo
00:46:30@21/08/2014@João da Silva@são Paulo
How can I read this file, using this same function above and put everything inside a LISTVIEW ?
Related: Explodes in Delphi
Just to get rich, Tstringlist owns the properties Delimite and the delimitedText. This is very useful for creating a Tstringlist from a string with delimiters.
– Edgar Muniz Berlinck
Yes, you must set the delimite and then the delimitedText in place of text with replace.
– Edgar Muniz Berlinck
@Bacco, there’s only one problem in this second code, when the client has spaces, he doesn’t work, like Carlos dos Santos, he only captures Carlos.
– user7605
@Bacco, with the Delimitedtext version, the "ancient" mode works perfectly...
– user7605