delux
delux

Reputation: 1876

Convert string to unicode in C#?

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

Upvotes: 0

Views: 489

Answers (1)

Jasper Kent
Jasper Kent

Reputation: 3676

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)

Upvotes: 2

Related Questions