So, jetzt das Ganze mal mit FileStreams:
Delphi-Quellcode:
procedure AppendString(FS : TFileStream; StrReplace : String);
var
I : Integer;
begin
for I := 0 to Length(StrReplace) - 1 do
begin
FS.Write(StrReplace[i + 1], 1);
end;
end;
procedure TfrmMain.btnConvertClick(Sender: TObject);
var
I : Integer;
OneCharOfFile : Char;
INPUT_FILE : TFileStream;
OUTPUT_FILE : TFileStream;
HtmlTag : Boolean;
begin
HtmlTag := False;
INPUT_FILE := TFileStream.Create('D:\Test\index.html', fmOpenRead);
OUTPUT_FILE := TFileStream.Create('D:\Test\index_neu.html', fmCreate);
for I := 0 to INPUT_FILE.Size - 1 do
begin
INPUT_FILE.Position := I;
INPUT_FILE.Read(OneCharOfFile, 1);
case OneCharOfFile of
// <
'<' : HtmlTag := True;
// >
'>' : HtmlTag := False;
end;
if not HtmlTag then
begin
case OneCharOfFile of
// ä
'ä' : AppendString(OUTPUT_FILE, 'ä');
// Ä
'Ä' : AppendString(OUTPUT_FILE, 'Ä');
// ö
'ö' : AppendString(OUTPUT_FILE, 'ö');
// Ö
'Ö' : AppendString(OUTPUT_FILE, 'Ö');
// ü
'ü' : AppendString(OUTPUT_FILE, 'ü');
// Ü
'Ü' : AppendString(OUTPUT_FILE, 'Ü');
else
AppendString(OUTPUT_FILE, OneCharOfFile);
end;
end
else
begin
AppendString(OUTPUT_FILE, OneCharOfFile);
end;
end;
FreeAndNil(INPUT_FILE);
FreeAndNil(OUTPUT_FILE);
end;
Gibt es da jetzt noch Möglichkeiten den Code zu optimieren?