Einzelnen Beitrag anzeigen

japetos

Registriert seit: 30. Aug 2005
Ort: Montreal
58 Beiträge
 
#1

Zeichen in Textdatei ersetzen

  Alt 17. Okt 2005, 21:27
Das ist mein Code:

Delphi-Quellcode:
function file2string(filename:string):string;
var f: file of char;
    c:char;
begin
   result := '';
   if fileexists(filename) then
   begin
     assignfile(f,filename);
     reset(f);
     while not eof(f) do
     begin
       read (f,c);
       result := result + c;
     end;
     closefile(f);
   end;
end;

 
function strreplace(s,what, whit:string; var count:integer):string;
var lastfound: integer;
begin
   count := 0;
   result := s;
   if (what = '') or (whit = '') then exit;
   lastfound := 0;
   while pos(uppercase(what), uppercase(copy(result,lastfound+1,length(result)))) > 0 do
   begin
     inc(count);
     lastfound := lastfound + pos(uppercase(what), uppercase(copy(result,lastfound+1,length(result))));
     result := copy(result,1,lastfound-1) + whit + copy(result,lastfound + length(what),length(result));
     lastfound := lastfound - (length(what)-length(whit));
   end;
end;

function string2file(filename, aString: string; appendmode:boolean):boolean;
var f: textfile;//file of char;
    i : integer;
begin
   assignfile(f,filename);
   if appendmode then append(f) else rewrite(f);
   for i := 1 to length(aString) do
     write(f,astring[i]);
   closefile(f);
   result := true;
end;


procedure TForm1.okButtonClick(Sender: TObject);
var
 dateiname: string;
 mystring: string;
 c: integer;
begin
   dateiname := 'gbuch.txt';
   mystring := strreplace(mystring,'@','[at]',c);
   string2file('gbuch.txt', myString, false);
   showmessage('es wurden ' + inttostr(c) + ' einträge ersetzt');
   //IdFTP1.Put(dateiname, dateiname);
end;
Leider werden die Zeichen nicht ersetzt, sondern es wird alles geloescht.
Kann mir jemand helfen?
  Mit Zitat antworten Zitat