isAnsi/de
Zurück zur Seite Code Beispiele.
Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine ANSI-Datei handelt.
Mit dieser Methode werden auch ASCII-Dateien als ANSI-Dateien erkannt.
Eine 100 prozentige Methode, eine Textdatei zweifelsfrei als ANSI-Datei zu erkennen, gibt es nicht.
uses
FileUtil, ...;
...
function isAnsi(const conStrQuellDateiname: string): boolean;
var
txtQuelldatei: file of char;
chrZeichen: char;
begin
Result := False;
AssignFile(txtQuelldatei, UTF8ToSys(conStrQuellDateiname));
Reset(txtQuelldatei);
while not EOF(txtQuelldatei) do
begin
Read(txtQuelldatei, chrZeichen);
if (chrZeichen < #32) and (not (chrZeichen in [#9, #10, #13, #26])) then
begin
closefile(txtQuelldatei);
exit;
end;
end;
Result := True;
closefile(txtQuelldatei);
end;Aufruf unter Windows:
...
if isAnsi('E:\Test.txt') = True then
...
...Aufruf unter Linux:
...
if isAnsi('/home/user/Test.txt') = True then
...
...From the Free Pascal wiki, page "isAnsi/de", as it stood on 2020-02-18 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.
Edited on wiki.freepascal.org by 4 people, 2013–2020
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Olaf | Created page | |
| Billyraybones | (minor) | |
| Olaf | (minor) | |
| FTurtle | ||
| Trev | Fixed syntax highlighting; deleted category included in page template (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
