0

I'm in the process of learning more about Unicode. Could someone please demonstrate how to translate a code point value to a character string and vice-versa.

For example: How do you convert U+0037 to its character or string representation which is 7.

Please also show how to do this for ascii. For example: convert   to its character or string representation which is a space.

4
  • It's easy enough to parse the string and then use chr() to get a character. That will be fine for code points in the BMP. HTML entities are something else altogether. Commented Aug 5, 2014 at 7:07
  • David is it as simple as s:=chr(' ') or maybe s:=chr('U+0037');? Commented Aug 5, 2014 at 7:13
  • First of all you have to read the docs of chr(). Then parse the code point ordianl out of 'U+0037'. And html entities are completely different. Get a database of those. Commented Aug 5, 2014 at 7:20
  • Yeah had feeling I was gonna need some database but I thought delphi would come with one. Well I guess I will have to search for a Unicode Table online and parse it. Commented Aug 5, 2014 at 7:28

2 Answers 2

6

Delphi strings already use Unicode (UTF16) encoding, so there is no need to "convert" delphi strings to Unicode. Here is an example how to insert a Unicode representation of nbsp (U+00A0) and '7' (U+0037') into a delphi string directly:

procedure TForm1.Button1Click(Sender: TObject); const U_nbsp = $00A0; U_7 = $0037; var S: string; begin S:= 'abcd' + Char(U_nbsp) + Char(U_7); ShowMessage(S); end; 
Sign up to request clarification or add additional context in comments.

9 Comments

Sir, I see the use of const, but what if you don't know the item you are going to decode?
@megatr0n replace const by var?
@megatr0n If you have the Unicode jump code in U+0000 format, you can parse it for the hex digits then use the StrToInt() function to convert it to an integer.
@megatron However it does not solve the   related problem, because it is not a Unicode jumpcode representation.
@DavidHeffernan: Chr is, in effect, a cast. It does not produce any code (except the usual Byte to Word expansion, which the cast would produce too), AFAICT.
|
0
procedure TFrm.FormCreate(Sender: TObject); begin TabEmoj.Text:=#$1F604; KeyEmojisActivator.Text:=#$1F604; Attachbutton.Text:=#$1F4CE; VideoAudiobutton.Text:=#$1F3A5; /// MIC = #$1F3A4; EnterButton.Text:=#$21A9; end; // use this. Download example on u9.by 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.