Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 3-4-2020. The page as it is now.

Utf8File To AnsiFile/de

Zurück zur Seite Code Beispiele.

Das Unterprogramm konvertiert eine UTF8-Datei in eine Ansi-Datei.

pascal
uses
  FileUtil, Classes, ...;

  ...

procedure subDekodiereUtf8DateiZuAnsiDatei(
  const conStrQuellDatei, conStrZielDatei: string);
var
  strlStringlist: TStringList;
  strPuffer: String;

begin

  strlStringlist := TStringList.Create;
  strlStringlist.LoadFromFile(Utf8ToSys(conStrQuellDatei));

  // Wenn BOM vorhanden, dann entfernen
  if Copy(strlStringlist[0], 1, 3) = #$EF#$BB#$BF then
  begin
    strPuffer := strlStringlist[0];
    Delete(strPuffer, 1, 3);
    strlStringlist[0] := strPuffer;
  end;

  // Konvertiert die Stringliste von UTF8 nach Ansi
  strlStringlist.Text := UTF8ToAnsi(strlStringlist.Text);
  strlStringlist.SaveToFile(Utf8ToSys(conStrZielDatei));

  FreeAndNil(strlStringlist);

end;

Aufruf unter Windows:

pascal

  ...

  subDekodiereUtf8DateiZuAnsiDatei('E:\Test.txt', 'E:\Test1.txt');

  ...

Aufruf unter Linux:

pascal

  ...

  subDekodiereUtf8DateiZuAnsiDatei('/home/user/Test.txt', '/home/user/Test1.txt') then 

  ...

From the Free Pascal wiki, page "Utf8File To AnsiFile/de", as it stood on 2020-03-04 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.