Thank you,
Strings are now parsed correctly and show up in their correct locations in
a TStringGrid.
John
St:= TStringList.Create;
try
//Example lines '00,INITIAL,NOP, 000000, 000000,04,INC,GTF,MTF,ATF.'
// '04,SKIP,NOP, 000000, 000000,00.'
i := LastDelimiter('.',buf);
Delete(buf, i, 1); // remove period at end of line.
St.CommaText := buf;
trainid := StrToInt(St[0]);
Cells[1,trainid+1] := St[1];
items := StrToInt(St[5]);
if (items <> 0) then begin
for i:= 6 to items+5 do
Cells[i-4, trainid+1] := St[i];
end;
finally
St.Free;
end;
Automation Artisans Inc.
http://www.autoartisans.com/ELS/
Ph. 1 250 544 4950
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Monir-SitesPower
> Sent: Thursday, October 23, 2008 2:02 AM
> To: 'Borland's Delphi Discussion List'
> Subject: RE: Parsing strings.
>
>
> Since it is comma separator data, use TStringList to parse as follow:
>
> var St: TStringList;
> i: integer;
>
> begin
> St:= TStringList.Create;
> Try
> St.CommaText:= '00,INITIAL,NOP, 000000,
> 000000,04,INC,GTF,MTF,ATF.';
> for i:=0 to St.Count-1 do
> // now the substring is in (for strings :St[i] , and for numbers
> :IntToStr(St[i] )
> Finally
> St.Free;
> end;
> end;
>
>
> Monir
>
> -----Original Message-----
> Sent: Thursday, October 23, 2008 5:16 AM
> To: 'Borland's Delphi Discussion List'
> Subject: Parsing strings.
>
> Short of doing the usual substring etc. and breaking the
> string below into
> smaller ones and then using val() to grab the numbers is
> there something
> equivalent to sscanf() in Delphi?
>
> '00,INITIAL,NOP, 000000, 000000,04,INC,GTF,MTF,ATF.'
>
> Thanks
>
> John
>
> Automation Artisans Inc.
> http://www.autoartisans.com/ELS/
> Ph. 1 250 544 4950
>
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
>
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
>
>
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi