Re: delimit string in a textfile

From: Ante Smolcic (spam_at_supersmola.net)
Date: 10/31/04


Date: Sun, 31 Oct 2004 15:15:53 +0100

In article <6a15bfbe.0410310329.6555d9bf@posting.google.com>,
harald_thomsen@yahoo.com says...
> Hi,
> I got a textfile that i'm reading into variables.
> The file looks like this:
>
> S: : : 1: 8:28/10/04 08:30:14: 16:
> 1:900030=:30:10000:4:1000:0:0:0:0:1:1:"":0:""
> S: : : 1: 9:28/10/04 08:30:21: 16:
> 1:900030=:30:7500:1:1000:0:0:0:0:1:1:"":0:""
> S: : : 1: 13:28/10/04 08:31:14: 16:
> 1:2069670000008:49:7525:1:4192:0:169:0:0:1:1:"":2069670075259:""
> S: : : 1: 14:28/10/04 08:31:18: 16:
> 1:2068130000008:49:1230:1:62:0:0:0:0:1:1:"":2068130012308:""
> S: : : 1: 18:28/10/04 08:31:25: 16:
> 1:421=:30:1580:4:1000:0:118:0:0:1:1:"":0:""
> S: : : 1: 19:28/10/04 08:31:27: 16:
> 1:5704068025016:47:1095:1:1000:0:0:0:0:1:1:"":0:""
> E: : : 1: 24:28/10/04 08:31:42: 16: 1:85:0:76875:""
> T: : : 1: 28:28/10/04 08:31:46: 16: 1:7:76875:1:0:0:"17"
> I: : : 1: 29:28/10/04 08:31:46: 16:
> 1:27:77060:0:0:0:0:1:76875:0:0:0:0:1
> E: : : 1: 30:28/10/04 08:31:46: 16: 1:84:0:0:""
> E: : : 1: 31:28/10/04 08:34:14: 16: 0:90:83:0:""
>
>
> Every line starts with a letter.
> In the first half I can use
> date := copy(S, 20, 8)
> as the colons are in fixed places.
>
> Can I find the colons using Pos, and then use Copy to get it?
>
> Not sure how it's done.
>

You can set the lines through TStrings.DelimitedText property and have
it separate values for you:

MyStringList, MyDelimited : TStringList;

...

MyStringList.Load('file.txt')
MyDelimited.Delimiter := ':';
MyDelimited.QuoteChar := '"';

for i := 0 to MyStringList.Count - 1 do
begin
  MyDelimited.DelimitedText := MyStringList[i];
  // now MyDelimited contains as many lines as were values in
  // MyStringList[i]
end;

-- 
I offered ugly death to everyone I met, and I did it with a song in my 
heart.


Relevant Pages

  • Re: delimit string in a textfile
    ... "ht" schreef in bericht ... > I got a textfile that i'm reading into variables. ... > Can I find the colons using Pos, and then use Copy to get it? ...
    (comp.lang.pascal.delphi.misc)
  • delimit string in a textfile
    ... I got a textfile that i'm reading into variables. ... Can I find the colons using Pos, and then use Copy to get it? ... Regards, ...
    (comp.lang.pascal.delphi.misc)
  • Re: changing the date format in vb.net
    ... important for vb.net when reading a date in plain tekst in a textfile ... When I change the windows format in dd/mm/yyyy than the date is reading. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Textfile
    ... Is there a chance to change only one column in a textfile without reading ... then each member of the column would sit on a disk block boundary ...
    (comp.soft-sys.matlab)
  • Re: Textfile
    ... Is there a chance to change only one column in a textfile without reading ... then each member of the column would sit on a disk block boundary ...
    (comp.soft-sys.matlab)