开发者

Reading unicode characters from text file in Delphi 2009

开发者 https://www.devze.com 2022-12-21 06:41 出处:网络
I have the following piece of code to read Japanese Kanji characters from UTF-8 format Text file and then load it into Memo.

I have the following piece of code to read Japanese Kanji characters from UTF-8 format Text file and then load it into Memo.

Var F:textFi开发者_如何学JAVAle;
S:string;
Begin
 AssignFile(F,'file.txt');
 Reset(F);
 While not EoF(F) do
 Begin
  Readln(F,S);
  Memo1.Lines.Add(S);
 End;
 CloseFile(F);
End;

But instead of characters I see some set of totally different symbols, not related to Japanese set. Any hints?


Use Memo1.Lines.LoadFromFile, or LoadFromStream. TextFile is still using ANSI even in Delphi 2009.


You need to convert to UTF-16, which windows uses, before using your strings.

Edit: Some googling yields the function UTF8ToWideString.

0

精彩评论

暂无评论...
验证码 换一张
取 消