【问题标题】:Reading from file FreePascal从文件 FreePascal 中读取
【发布时间】:2013-03-05 01:27:16
【问题描述】:

所以我的文本文件包含:

Harry Potter and the Deathly Hallows###J. K. Rowling###2007

而且我必须以如下形式输出到 FreePascal 程序

J.K.Rowling "Harry Potter and the Deathly Hallows" 2007 year

我知道如何从文件中读取,但我不知道如何使它像以前的表单一样

有人可以帮助我吗?非常感谢。

【问题讨论】:

标签: pascal freepascal


【解决方案1】:

如果 freepascal 中的 TStringList 与 Delphi 中的相同,那么这样就可以解决问题:

function SortedString( const aString : String) : String;
var
  sList : TStringList;
begin
  Result := '';
  sList := TStringList.Create;
  try
    sList.LineBreak := '###';
    sList.Text := aString;
    if (sList.Count = 3) then
    begin
      Result := sList[1] + ' "' + sList[0] + '" ' + sList[2] + ' year';
    end;
  finally
    sList.Free;
  end;
end;

更新,正如 @TLama 所评论的,freepascal TStringList 没有 LineBreak 属性。

试试这个(在 StrUtils 中使用 ReplaceStr):

function SortedString(const aString : String) : String;
var
  sList : TStringList;
begin
  Result := '';
  sList := TStringList.Create;
  try 
    sList.Text := ReplaceStr(aString,'###',#13#10);
    if (sList.Count = 3) then
    begin
      Result := sList[1] + ' "' + sList[0] + '" ' + sList[2] + ' year';
    end;
  finally
    sList.Free;
  end;
end;

【讨论】:

  • 恐怕不是;我在 FPC 2.6.0 (Lazarus 1.0 RC2) 中检查了这一点,TStringList 没有可用的 LineBreak 属性。
猜你喜欢
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-02
  • 2017-06-28
  • 2012-05-15
  • 2016-06-18
相关资源
最近更新 更多