Click here to Skip to main content
14,870,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would I go about taking a string and turning it into unicode characters like this:
(originally abcdef) 0061 0062 0063 0064 0065 0066

What I have tried:

I've already looked online for an answer, but all of the answers only allow you to change chars. (and they all look like \u0061\u0062\u0063\u0064\u0065\u0066)
Posted
Updated 26-Sep-20 11:03am

If you mean "how do I print a string as the hex representation of each Unicode character?" then it's pretty trivial:
C#
string s = "abcdef";
StringBuilder sb = new StringBuilder(s.Length * 5);
foreach (char c in s)
    {
    sb.Append ($"{(int)c:X4} ");
    }
Console.WriteLine(sb.ToString());
   
Quote:
How do I convert a string into unicode in C#

You need to give more detail, because there is more than 1 unicode.
Quote:
How would I go about taking a string and turning it into unicode characters like this:
(originally abcdef) 0061 0062 0063 0064 0065 0066

The problem is than this is already unicode, particularly, it is UTF16
UTF-16 - Wikipedia[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900