PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] How to convert emoji's unicode strings-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] How to convert emoji's unicode strings

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    823

    Resolved [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

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,400

    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:
    1. var text = $"U+{number:X}";
    or:
    csharp Code:
    1. var text = "U+" + number.ToString("X");
    The 'X' format specifier indicates upper-case hexadecimal.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,400

    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:
    1. var number = Convert.ToInt32(text.Substring(2), 16);
    or:
    csharp Code:
    1. var number = int.Parse(text.Substring(2), NumberStyles.HexNumber);

  4. #4

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    823

    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();

  5. #5

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    823

    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();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width