Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Dostounix (https://www.delphipraxis.net/178432-dostounix.html)

bernhard_LA 8. Jan 2014 12:52

Dostounix
 
Hat jemand mal ein schöne Implementierung für DOSTOUNIX ??

UNIX2DOS habe ich schon


Delphi-Quellcode:
procedure Unix2Dos(UnixTEXTFile, DosTEXTFile : String);
Const CR : Char = #13;
      LF = #10;
Var InFile, OutFile : File;
    InByte : Char;

begin
  Assign (InFile, UnixTEXTFile); ReSet  (InFile, 1);
  Assign (OutFile, DosTEXTFile); ReWrite (OutFile, 1);
  while NOT EOF (InFile) do
    begin
      BlockRead (InFile, InByte, 1);
      if InByte = LF then BlockWrite (OutFile, CR, 1);
      BlockWrite (OutFile, InByte, 1);
    end;
  Close (OutFile);
  Close (InFile);
end;

Mikkey 8. Jan 2014 12:58

AW: Dostounix
 
Wenn es bei dem Muster bleiben soll:

Delphi-Quellcode:
      if InByte <> CR then
        BlockWrite (OutFile, InByte, 1);
Macht allerdings keinen besonders performanten Eindruck.

guinnes 8. Jan 2014 13:06

AW: Dostounix
 
Zitat:

Zitat von bernhard_LA (Beitrag 1242661)
Hat jemand mal ein schöne Implementierung für DOSTOUNIX ??

UNIX2DOS habe ich schon


Delphi-Quellcode:
procedure Unix2Dos(UnixTEXTFile, DosTEXTFile : String);
Const CR : Char = #13;
      LF = #10;
Var InFile, OutFile : File;
    InByte : Char;

begin
  Assign (InFile, UnixTEXTFile); ReSet  (InFile, 1);
  Assign (OutFile, DosTEXTFile); ReWrite (OutFile, 1);
  while NOT EOF (InFile) do
    begin
      BlockRead (InFile, InByte, 1);
      if InByte = LF then BlockWrite (OutFile, CR, 1);
      BlockWrite (OutFile, InByte, 1);
    end;
  Close (OutFile);
  Close (InFile);
end;

Warum solch einen Zirkus ? In eine Stringliste einlesen und mit SaveToFile wieder speichern und gut ist

Sir Rufo 8. Jan 2014 16:26

AW: Dostounix
 
Vor allem macht das Sinn, wenn man eine Textdatei mit einem Multibyte-Encoding verarbeiten will ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:29 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz