Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to convert emoji's unicode strings

How to convert emoji's unicode strings

Scheduled Pinned Locked Moved C#
csharphtmlasp-netcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    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

    OriginalGriffO 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      V 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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!

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups