找了好久,發現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;