Sign in Join
Wiki copytemporary

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

isAscii/de

Zurück zur Seite Code Beispiele.

Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine ASCII-Datei handelt.

pascal
uses
  FileUtil, ...;

  ...

function isAscii(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]))) or (chrZeichen > #127) then
    begin
      closefile(txtQuelldatei);
      exit;
    end;

  end;

  Result := True;
  closefile(txtQuelldatei);

end;

Aufruf unter Windows:

pascal

  ...

  if isAscii('E:\Test.txt') = True then
    ...

  ...

Aufruf unter Linux:

pascal

  ...

  if isAscii('/home/user/Test.txt') = True then
    ...

  ...

From the Free Pascal wiki, page "isAscii/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.