I am trying to convert a String
object containing a string representing an emoticon's Unicode format into a String
with the same emoticon represented by the Unicode as its only character, e.g. converting "\u1F34E"
to 🍎
.
I attempted the following under the supposition the string's escape sequence would be properly processed:
String str = "\u1F34E";
Console.WriteLine("'{0}' to '{1}'", str, str.ToCharArray()[0]);
Output:
'\u1F34E' to '\'
Outputting the string directly to a text file yields the same result, so it is not just the debugger I am using. I am unsure what to do. Any help would be greatly appreciated.
EDIT:
I realize my original question was not clear; my intent was to have a properly formatted UTF-16 string with a UTF-32 unicode within a string, as an API I was sending this value to required this formatting. I have successfully resolved the problem with the following:
String str = "1F34E"; //removed \u with prior parsing
int unicode_utf32 = int.Parse(stdemote.Unicode, System.Globalization.NumberStyles.HexNumber);
String unicode_utf16_str = Char.ConvertFromUtf32(unicode_utf32);
Console.WriteLine("'{0}' to '{1}'", str, unicode_utf16_str);