天天看点

lazarus:多行文本保存为UTF8格式

    找了好久,发现Lazarus中已经有这个函数。

uses 

    LazUTF8Classes;

......

SaveStringsToFileUTF8(stringList.Lines, 'aaa.csv'); 

这个单元中还有好几个相关的函数:

 { TFileStreamUTF8 }

  TFileStreamUTF8 = class(TFileStream)

  private

    FFileName: string;

  public

    constructor Create(const AFileName: string; Mode: Word);

    constructor Create(const AFileName: string; Mode: Word; Rights: Cardinal);

    property FileName: string Read FFilename;

  end;

  { TStringListUTF8 }

  TStringListUTF8 = class(TStringList)

  protected

    function DoCompareText(const s1,s2 : string) : PtrInt; override;

  public

    procedure LoadFromFile(const FileName: string); override;

    procedure SaveToFile(const FileName: string); override;

  end;

  { TMemoryStreamUTF8 }

  TMemoryStreamUTF8 = class(TMemoryStream)

  public

    procedure LoadFromFile(const FileName: string);

    procedure SaveToFile(const FileName: string);

  end;

procedure LoadStringsFromFileUTF8(List: TStrings; const FileName: string);

procedure SaveStringsToFileUTF8(List: TStrings; const FileName: string);

function CompareStringListItemsUTF8LowerCase(List: TStringList; Index1, Index2: Integer): Integer;