[function]將UTF8String寫入unicode檔案的函數

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[function]將UTF8String寫入unicode檔案的函數

文章 tim »

利用 TFileStream 配合 UTF8String 寫入成 UTF-8 的的文字檔

語法:

代碼: 選擇全部

     
    function WriteUTF8String2File(filename: string; us: UTF8String):Boolean; 
    var 
      wf: Array[0..2] of Char; 
      f: TFileStream; 
    begin 
      Result := false; 
      wf[0]:=#$EF; 
      wf[1]:=#$BB; 
      wf[2]:=#$BF; 
      f:= TFileStream.Create(filename, fmCreate); 
      try 
        f.Write(wf, 3); 
        f.Write(PChar(us)^, length(us)); 
        Result := true; 
      finally 
        f.Free; 
      end; 
    end; 




參考文章: http://delphi.ktop.com.tw/topic.asp?TOPIC_ID=65174
多多留言, 整理文章, 把經驗累積下來.....
回覆文章