开发者

how to show hex code char?

i have a file contains numbers like FB8E,FB8F,FB90 on each line.

i want in my program to load this file and take each line and print the character corresponded to that number/line.

for expamle, my firnst line is FB8E,开发者_Go百科 i want something to convert it like #$FB8E (arabic Kaf), how do i do that?


If you are in D2009/2010:

var
  F: TextFile;
  Line: string;
  Code: Integer;
  Ch: Char;

...
Readln(F, Line);
Code := StrToInt('$' + Line);
Ch := Char(Code);
...

otherwise replace Char with WideChar.

Of course the code can be compressed a little bit, but I left this out for clarity.

EDIT: For those of you being not afraid of type casting there is also the HexToBin function in classes.pas.


You won't be too happy with simply converting the line to #$FB8E as the compiler most likely sorts these out for you.

So the general approach here would be to read the line, parse the hex value and create a WideChar from that value. But I didn't do much Delphi in recent years so I'm afraid I can't tell you exactly how to do this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜