Utf8File To AnsiFile/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Utf8File To AnsiFile/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Zurück zur Seite [[code examples/de|Code Beispiele]]. | |
| 2 | + | ||
| 3 | + | Das Unterprogramm konvertiert eine UTF8-Datei in eine Ansi-Datei. | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | uses | |
| 7 | + | FileUtil, Classes, ...; | |
| 8 | + | ||
| 9 | + | ... | |
| 10 | + | ||
| 11 | + | procedure subDekodiereUtf8DateiZuAnsiDatei( | |
| 12 | + | const conStrQuellDatei, conStrZielDatei: string); | |
| 13 | + | var | |
| 14 | + | strlStringlist: TStringList; | |
| 15 | + | strPuffer: String; | |
| 16 | + | ||
| 17 | + | begin | |
| 18 | + | ||
| 19 | + | strlStringlist := TStringList.Create; | |
| 20 | + | strlStringlist.LoadFromFile(Utf8ToSys(conStrQuellDatei)); | |
| 21 | + | ||
| 22 | + | // Wenn BOM vorhanden, dann entfernen | |
| 23 | + | if Copy(strlStringlist[0], 1, 3) = #$EF#$BB#$BF then | |
| 24 | + | begin | |
| 25 | + | strPuffer := strlStringlist[0]; | |
| 26 | + | Delete(strPuffer, 1, 3); | |
| 27 | + | strlStringlist[0] := strPuffer; | |
| 28 | + | end; | |
| 29 | + | ||
| 30 | + | // Konvertiert die Stringliste von UTF8 nach Ansi | |
| 31 | + | strlStringlist.Text := UTF8ToAnsi(strlStringlist.Text); | |
| 32 | + | strlStringlist.SaveToFile(Utf8ToSys(conStrZielDatei)); | |
| 33 | + | ||
| 34 | + | FreeAndNil(strlStringlist); | |
| 35 | + | ||
| 36 | + | end; | |
| 37 | + | ``` | |
| 38 | + | ||
| 39 | + | Aufruf unter Windows: | |
| 40 | + | ||
| 41 | + | ``` pascal | |
| 42 | + | ||
| 43 | + | ... | |
| 44 | + | ||
| 45 | + | subDekodiereUtf8DateiZuAnsiDatei('E:\Test.txt', 'E:\Test1.txt'); | |
| 46 | + | ||
| 47 | + | ... | |
| 48 | + | ``` | |
| 49 | + | ||
| 50 | + | Aufruf unter Linux: | |
| 51 | + | ||
| 52 | + | ``` pascal | |
| 53 | + | ||
| 54 | + | ... | |
| 55 | + | ||
| 56 | + | subDekodiereUtf8DateiZuAnsiDatei('/home/user/Test.txt', '/home/user/Test1.txt') then | |
| 57 | + | ||
| 58 | + | ... | |
| 59 | + | ``` | |
| 60 | + | ||
| 61 | + | --- | |
| 62 | + | *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](/wiki-contact).* |
