Re: data from text extraction
Posted by WAllison on December 06, 2001 at 05:19:30:
In Reply to: data from text extraction posted by Rob Pouwelse on November 08, 2001 at 14:43:19:
: I've got a question..:
: how can i extract certain values (int's or string's) from a text file??
: it's like this:
: now i have to extract certain values (the ones behind the "=" but not all)
: I haven't the foggiest on how to do it..
//no frills - dunno how reliable this one is - but it gives u an idea of how to approach the problem.
function TMainForm.GetDataStrings(FileName: string; DataList: TStringList): boolean; var F: TextFile; APos, BPos: Integer; s, s1: string; begin Result := False; AssignFile(F, FileName); Reset(F); While not EOF(F) do begin ReadLn(F, s);
APos := Pos('=', s); While (s[APos] <> ' ') do APos := APos - 1; APos := APos + 1; s := copy(s, APos, Length(s));
While Length(s) > 0 do begin BPos := Pos(',', s);
//Copy the data s1 := copy(s, 0, BPos - 1); DataList.Add(s1);
//Remove the first entry delete(s, 1, BPos + 1); end; Result := DataList.Count > 0; end; CloseFile(F); end;