[function]將WideString寫入unicode檔案的函數
發表於 : 2008年 11月 28日, 14:00
利用 TFileStream 配合 WideString 寫入成 unicode 的 littel endian 的文字檔
參考文章: http://delphi.ktop.com.tw/topic.asp?TOPIC_ID=46228
代碼: 選擇全部
function WriteWideString2File(filename: string; ws: WideString):Boolean;
const
WideBOM_LSB_First = WideChar(#$FEFF);
var
wf: WideString;
f: TFileStream;
i: integer;
begin
Result := false;
wf := WideBOM_LSB_First;
f:= TFileStream.Create(filename, fmCreate);
try
f.Write(wf[1], 2);
//for i:= 1 to length(ws) do
// f.Write(ws[i], sizeof(ws[i]));
f.Write(PWideChar(ws)^, length(ws)*sizeof(WideChar));
Result := true;
finally
f.Free;
end;
end;
參考文章: http://delphi.ktop.com.tw/topic.asp?TOPIC_ID=46228