从文件FreePascal读取 [英] Reading from file FreePascal

查看:175
本文介绍了从文件FreePascal读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的文本文件包含:

So I have text file containing:

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

我必须以以下形式将其输出到FreePascal程序

And I have to output it to the FreePascal program in the following form

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

我知道如何从文件中读取文件,但我不知道如何使其以previos格式显示

I know how to read from file but I don't know how to make it like in the previos form

有人可以帮助我吗?我会非常感激.

Can someone help me? I would be very thankful.

推荐答案

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

If TStringList in freepascal is the same as in Delp then this would do the trick:

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属性.


Update, as commented by @TLama, freepascal TStringList does not have a LineBreak property.

请改用此方法(在StrUtils中使用ReplaceStr):

Try this instead (using ReplaceStr in StrUtils):

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;

这篇关于从文件FreePascal读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆