-
Apr 5th, 2019, 01:58 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] How to convert emoji's unicode strings
Good Day All
i have a unicode character which works very well
/// Thinking face 🤔
/// </summary>
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/...moji-list.html)
but the code in that website is "U+1F914"
how do i convert U+1F914 to 0x1f914 in c#
thanks
-
Apr 5th, 2019, 02:05 AM
#2
Re: How to convert emoji's unicode strings
The '0x' is part of the code, not part of the value. It's just how hexadecimal literals are indicated in code, just like double quotes around text indicates a string literal and single quotes a char literal. If you want a string that contains "U+1F914" from that number then you would use something like this:
csharp Code:
var text = $"U+{number:X}";
or:
csharp Code:
var text = "U+" + number.ToString("X");
The 'X' format specifier indicates upper-case hexadecimal.
-
Apr 5th, 2019, 02:12 AM
#3
Re: How to convert emoji's unicode strings
Hmmm... I think I may have misinterpreted the question and got it the wrong way around. Are you saying that you want to get a number from the text? If so then something like this:
csharp Code:
var number = Convert.ToInt32(text.Substring(2), 16);
or:
csharp Code:
var number = int.Parse(text.Substring(2), NumberStyles.HexNumber);
-
Apr 5th, 2019, 07:12 AM
#4
Thread Starter
Fanatic Member
Re: How to convert emoji's unicode strings
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
Code:
txtresults.Text = txttext.Text.Replace("U+", "0x").ToLower();
-
Apr 5th, 2019, 07:13 AM
#5
Thread Starter
Fanatic Member
Re: How to convert emoji's unicode strings
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
Code:
txtresults.Text = txttext.Text.Replace("U+", "0x").ToLower();
-
Apr 3rd, 2020, 04:03 AM
#6
Lively Member
Re: [RESOLVED] How to convert emoji's unicode strings
Hello , @vuyiswamb
Please try this code,To convert emoji's unicode strings:
Code:
var convertStr = string.Join("-", Regex.Matches(res, @"..").Cast<Match>().ToList());
String[] tempArr = convertStr.Split('-');
byte[] decBytes = new byte[tempArr.Length];
for (int i = 0; i < tempArr.Length; i++)
{
decBytes[i] = Convert.ToByte(tempArr[i], 16);
}
String str = Encoding.BigEndianUnicode.GetString(decBytes);
I hope this code will be usefull for you.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|