65.9K
CodeProject is changing. Read more.
Home

Unicode/UTF-32: Get Character From Codepoint

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jan 2, 2011

CPOL
viewsIcon

10988

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.
<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!