Posted by Henry on April 16, 2006
In Reply to comparing string with strings posted by john on
April 11, 2006
If I understand you well, the function ReadFile should return the last line of the file, if that line is not found anywhere else in the file. This is done in the example below. If the last line is found somewhere else in the file, the function returns an empty string. Also returns empty string if the text file is not found.
function TForm1.ReadFile(FileName: string): string; var List: TStringList; LastLine: string; i: integer; begin Result := ''; if FileExists(FileName) then begin List := TStringList.Create; List.LoadFromFile(FileName); LastLine := List[List.Count - 1]; Result := LastLine; for i := 0 to List.Count - 2 do begin if List[i] = LastLine then begin Result := ''; break; end; end; List.Free; end else ShowMessage('File not found: ' + FileName); end;
Related Articles and Replies