Pascal 向文件类型添加空格

Pascal adding whitespace to file typed

我正在尝试向文件中写入内容,但 Pascal 在每条记录的值之间添加了一堆空格,并且还在一行中放置了 2 条记录。

第一个文件只是一个字符串列表。 第二个文件(我通过程序创建的那个)应该有标题和描述。

如何去除 Pascal 添加的空格?

program Wiki;
  {$mode objfpc}

TYPE wiki=record
    title:string;
    description:string;

  end;
var
  f:text ;
  g:file of wiki ;
  row:wiki;
  fileName: string;
  oldFileName:string;

begin
  writeln('Old file name:');
  readln(oldFileName);
  ASSIGN(f,oldFileName);
  RESET(f);
  writeln('New file name:');
  readln(fileName);
  ASSIGN(g,fileName);
  REWRITE(g);

REPEAT
  Readln(f,row.title);
  writeln('give a description:');
  Writeln(row.title);
  Readln(row.description);
  Write(g,row)

until EOF(f);

  CLOSE(f);
  CLOSE(g);
  writeln;
  writeln('press enter to close.');
  readln();
end.

在没有{$H+}objfpc模式下,我猜测row.description是固定大小的Turbo Pascal风格ShortString。它有 255 个字符长,这可能就是为什么你得到所有空白的原因。

而是将输出文件写为文本文件:

var
  f: Text;
  g: Text;

和:

Writeln(g, row.title, ';', row.description);

这应该会产生如下文本输出:

Finding Nemo;The adventures of two fish trying to find the lost son of one of them
Toy Story;The adventures of a merry bunch of toys     

等等