STALKER_HIGHLANDER
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору /////////////////////////////////////////////////////////////////////////////// // Find given text in given file, and replace // complete textline with given text. // Created: March 27, 2002 by S.T.I.Bracke // Revised: May 22, 2002 by S.T.I.Bracke function ReplaceLine(strFilename, strFind, strNewLine: String): Boolean; var strTemp : String; iLineCounter : Integer; a_strTextfile : TArrayOfString; begin { Load textfile into string array } LoadStringsFromFile(strFilename, a_strTextfile); { Search trough all textlines for given text } // old line // for iLineCounter := 1 to High(a_strTextfile) do // new line corrected by Nikolaus Moll for iLineCounter := 0 to GetArrayLength(a_strTextfile)-1 do begin { Overwrite textline when text searched for is part of it } if (Pos(strFind, a_strTextfile[iLineCounter]) > 0) then a_strTextfile[iLineCounter] := strNewLine; end; { Save string array to textfile (overwrite, no append!) } SaveStringsToFile(strFilename, a_strTextfile, False); Result := True; end; |