Int32 - ConvertFromUtf32
Converts the specified Unicode code point into a UTF-16 encoded string.
public static void Main() { int letterA = 0x0041; //U+00041 = LATIN CAPITAL LETTER A Console.WriteLine("Create a UTF-16 encoded string from a code point."); // C# Extension Method: Int32 - ConvertFromUtf32 string s1 = letterA.ConvertFromUtf32(); Console.Write(" 1a) 0x{0:X} => ", letterA); Show(s1); } private static void Show(string s) { for (int x = 0; x < s.Length; x++) { Console.Write("0x{0:X}{1}", (int)s[x], ((x == s.Length-1)? String.Empty : ", ")); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Converts the specified Unicode code point into a UTF-16 encoded string. /// </summary> /// <param name="utf32">A 21-bit Unicode code point.</param> /// <returns> /// A string consisting of one object or a surrogate pair of objects equivalent to the code point specified by /// the parameter. /// </returns> public static String ConvertFromUtf32(this Int32 utf32) { return Char.ConvertFromUtf32(utf32); } }