producing UTF-8 character by its code in Lazarus

69 Views Asked by At

How do I convert from '\342\204\226' (octal), 0xE2 0x84 0x96 (hex), to '№' character in Lazarus?

I can use notation edit3.caption:=#$E2#$84#$96 for constants, but I need it to work for variables. What function should I use?

Handling letters is easy:

var r1, r2: integer
begin
  edit3.caption:=#$D0#$A0; 
  edit3.caption:=chr(r1)+chr(r2);
end;

both put expected 'Р' into the edit control.

Chr(r1)+Chr(r2)+Chr(r3) produces some unexpected symbol.

1

There are 1 best solutions below

1
Marco van de Voort On

Seems the unicode value for that char is $2116, which is within the BMP, so a cast to widechar works:

edit3.caption:=widechar($2116);

or using chr:

edit3.caption:=chr($E2)+chr($84)+chr($96);

if you have trouble with variables, try making r1..r3 of type BYTE.