0

How can I get the unicode values (from the code column) if I have the string? For example, for passing the empty space " " I would like to get the value U+0020. I found this approach:

byte[] asciiBytes1 = Encoding.ASCII.GetBytes(" "); 

But this returns me the value from the decimal column.

enter image description here

3
  • 1
    You mean you want the string "U+0020" ? Commented Mar 22, 2020 at 20:04
  • ASCII is not unicode Commented Mar 22, 2020 at 21:07
  • A string consists of chars, which you can cast to a short (or int). This will give you more characters than ASCII (which has codes from 0 to just 127). But then you may run into "surrogate pairs" ... Commented Mar 23, 2020 at 7:36

1 Answer 1

2

If value is your decimal value:

string code = $"U+{value.ToString ("X4")}"; 

will give you what you want.

(X means hex, 4 means pad to 4 digits)

Sign up to request clarification or add additional context in comments.

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.