Sign in Join
Wiki copytemporary

isAnsi/de: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: isAnsi/de

OldNewLine
1+Zurück zur Seite [[code examples/de|Code Beispiele]].
2+
3+Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine ANSI-Datei handelt.
4+
5+Mit dieser Methode werden auch ASCII-Dateien als ANSI-Dateien erkannt.
6+
7+Eine 100 prozentige Methode, eine Textdatei zweifelsfrei als ANSI-Datei zu erkennen, gibt es nicht.
8+
9+``` pascal
10+uses
11+ FileUtil, ...;
12+
13+ ...
14+
15+function isAnsi(const conStrQuellDateiname: string): boolean;
16+var
17+ txtQuelldatei: file of char;
18+ chrZeichen: char;
19+
20+begin
21+
22+ Result := False;
23+ AssignFile(txtQuelldatei, UTF8ToSys(conStrQuellDateiname));
24+ Reset(txtQuelldatei);
25+
26+ while not EOF(txtQuelldatei) do
27+ begin
28+
29+ Read(txtQuelldatei, chrZeichen);
30+
31+ if (chrZeichen < #32) and (not (chrZeichen in [#9, #10, #13, #26])) then
32+ begin
33+ closefile(txtQuelldatei);
34+ exit;
35+ end;
36+
37+ end;
38+
39+ Result := True;
40+ closefile(txtQuelldatei);
41+
42+end;
43+```
44+
45+Aufruf unter Windows:
46+
47+``` pascal
48+
49+ ...
50+
51+ if isAnsi('E:\Test.txt') = True then
52+ ...
53+
54+ ...
55+```
56+
57+Aufruf unter Linux:
58+
59+``` pascal
60+
61+ ...
62+
63+ if isAnsi('/home/user/Test.txt') = True then
64+ ...
65+
66+ ...
67+```
68+
69+---
70+*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](/wiki-contact).*

Back to history