Click here to Skip to main content
15,885,546 members
Articles / Unicode
Tip/Trick

Unicode/UTF-32: Get Character From Codepoint

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 Jan 2011CPOL 10.7K   1  
If you ever need to get a character returned from a unicode string (such as "U+2A601") you can use the following method:

This will take care of not only UTF-16, but UTF-32 characters as well.

XML
<pre lang="c#">public static string ConvertUnicodeToCharacter(string unicodeValue)
        {
            int unicode = int.Parse(unicodeValue.Substring(2), NumberStyles.HexNumber);

            if (unicodeValue.Length == 7) //UTF-32
            {
                return char.ConvertFromUtf32(unicode);
            }

            return ((char)unicode).ToString(); //UTF-16
        }</pre>


Have fun!

License

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


Written By
Software Developer (Senior) Freelancer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --