home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / textfile.swg / 0050_Converting strings in Text files.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-02-28  |  2.8 KB  |  88 lines

  1. Program StrLenConv;
  2. Uses
  3.     Dos, Crt;
  4. Type
  5.     String_128  = String[128];
  6.     String_127  = String[127];
  7. Var
  8.    X,Y,StrPos  : Byte;
  9.    File128     : File of String_128;
  10.    File127     : File of String_127;
  11.    Str128      : String_128;
  12.    Str127      : String_127;
  13.    TempFile    : Text;
  14. Function  FileExist(FileName: String): Boolean;
  15.           Var
  16.              Tmpfile     : Text;
  17.              Attrib      : Word;
  18.           Begin {Function FileExist}
  19.                 If FileName = '' then
  20.                    Begin {If FileName = ''}
  21.                          FileExist := False; Exit;
  22.                    End;  {If FileName = ''}
  23.                 Assign(Tmpfile,FileName);
  24.                 GetFAttr(Tmpfile,Attrib);
  25.                 FileExist := (DosError = 0);
  26.           End;  {Function FileExist}
  27. Begin {Main}
  28.       TextMode(c80);
  29.       ClrScr;
  30.       Writeln('Source file with 128 character strings:');
  31.       Write(' ■ '); Readln(Str127);
  32.       If not(FileExist(Str127)) then
  33.          Begin {If not(FileExist(Str127))}
  34.                Writeln;
  35.                Writeln(' Error: ' + Str127 + ' does not exist.');
  36.                Halt(0);
  37.          End;  {If not(FileExist(Str127))}
  38.       Assign(File128,Str127);
  39.       Reset(File128);
  40.       Writeln;
  41.       Writeln('Destination file for 127 character strings:');
  42.       Write(' ■ '); Readln(Str127);
  43.       If FileExist(Str127) then
  44.          Begin {If FileExist(Str127)}
  45.                Writeln;
  46.                Writeln(' Error: ' + Str127 + ' already exists.');
  47.                Halt(0);
  48.          End;  {If FileExist(Str127)}
  49.       Assign(File127,Str127);
  50.       ReWrite(File127);
  51.       Assign(TempFile,'128TO127.TMP');
  52.       ReWrite(TempFile);
  53.       StrPos := 1;
  54.       Writeln;
  55.       Writeln('Reading Source File...');
  56.       Repeat
  57.             Read(File128,Str128);
  58.             For X := 1 to 128 do Writeln(TempFile,Str128[X]);
  59.       Until EOF(File128);
  60.       Reset(TempFile);
  61.       Close(File128);
  62.       Writeln;
  63.       Writeln('Writing Destination File...');
  64.       Repeat
  65.             For X := 1 to 127 do
  66.                 Begin {For X := 1 to 127}
  67.                       Readln(TempFile,Str128);
  68.                       Str127[X] := Str128[1];
  69.                 End;  {For X := 1 to 127}
  70.             Write(File127,Str127);
  71.       Until EOF(TempFile);
  72.       Close(File127);
  73.       Erase(TempFile);
  74.       Close(TempFile);
  75. End.  {Main}
  76.  
  77. Feel free to edit this however you like.  What it does (in a nutshell)
  78. is read a file which has 128 character strings, saves each character to
  79. a text file (one on a line), and then re-reads them into the 127
  80. character strings, writing each one to a file.
  81.  
  82. I hope this is what you were looking for.
  83.  
  84. Michael J. Church
  85. MC Squared Computing Technologies
  86. ---
  87.  ■ RNet 1.08R:■ NANET ■ After Five' BBS ■ Elkhart, IN ■ (219) 262-1370
  88.