简体   繁体   中英

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.

在此处输入图片说明

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM