How to convert emoji's unicode strings
-
Good Day All i have a unicode character which works very well /// Thinking face 🤔 /// UnicodeString Thinking =0x1f914; as you can see the value here is "0x1f914" so i use this site which has a list of emoji's [Full Emoji List, v12.0](http://www.unicode.org/emoji/charts/full-emoji-list.html) but the code in that website is "U+1F914" how do i convert U+1F914 to 0x1f914 in c# thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
-
Good Day All i have a unicode character which works very well /// Thinking face 🤔 /// UnicodeString Thinking =0x1f914; as you can see the value here is "0x1f914" so i use this site which has a list of emoji's [Full Emoji List, v12.0](http://www.unicode.org/emoji/charts/full-emoji-list.html) but the code in that website is "U+1F914" how do i convert U+1F914 to 0x1f914 in c# thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
Directly? You can't.
char
is a UTF-16 value: is can't hold values higher than 0xFFFF because it only has space for 16 bits - your emoji value is 17. You are going to have to do a lot more than just convert it to hex, you will have to start playing with UTF32: UTF32Encoding Class (System.Text) | Microsoft Docs[^] But to hex, or even an Int32 is simple:string siteCode = "U+1F914";
int i = Convert.ToInt32(siteCode.Replace("U+", "0x"), 16);Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Directly? You can't.
char
is a UTF-16 value: is can't hold values higher than 0xFFFF because it only has space for 16 bits - your emoji value is 17. You are going to have to do a lot more than just convert it to hex, you will have to start playing with UTF32: UTF32Encoding Class (System.Text) | Microsoft Docs[^] But to hex, or even an Int32 is simple:string siteCode = "U+1F914";
int i = Convert.ToInt32(siteCode.Replace("U+", "0x"), 16);Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
Good Day After i looked closely on the string , with lack of knowledge of the unicode stuff , i realized i just needed to replace the character and the emoji will be translated , the code below simply solved the problem
txtresults.Text = txttext.Text.Replace("U+", "0x").ToLower();
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com