megatr0n
megatr0n

Reputation: 362

How to convert a string or character to its unicode representation and back?

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.

Upvotes: 0

Views: 3169

Answers (2)

Piotr
Piotr

Reputation: 1

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

Upvotes: 0

kludg
kludg

Reputation: 27493

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;

Upvotes: 6

Related Questions