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. Unicode Code of a chracter

Unicode Code of a chracter

Scheduled Pinned Locked Moved C#
question
9 Posts 7 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.
  • L Offline
    L Offline
    Laji59
    wrote on last edited by
    #1

    How can I find a Unicode Code of a chracter in a string For exmple Unicode of (њ) is 5A 04 Is there any way to find it programmatically

    Hello Friends

    L G 2 Replies Last reply
    0
    • L Laji59

      How can I find a Unicode Code of a chracter in a string For exmple Unicode of (њ) is 5A 04 Is there any way to find it programmatically

      Hello Friends

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can use the Encoding class, like this: byte[] bytes = Encoding.UTF8.GetBytes("њ"); I haven't tested it, so the syntax might be a little bit different. regards

      L 1 Reply Last reply
      0
      • L Lost User

        You can use the Encoding class, like this: byte[] bytes = Encoding.UTF8.GetBytes("њ"); I haven't tested it, so the syntax might be a little bit different. regards

        L Offline
        L Offline
        Laji59
        wrote on last edited by
        #3

        Thanks alot. it worked Now I want to convert this code to hex. How can I do it?

        Hello Friends

        A 1 Reply Last reply
        0
        • L Laji59

          How can I find a Unicode Code of a chracter in a string For exmple Unicode of (њ) is 5A 04 Is there any way to find it programmatically

          Hello Friends

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Characters are unicode, so you can just convert it to int: int code = (int)'њ';

          Despite everything, the person most likely to be fooling you next is yourself.

          L 1 Reply Last reply
          0
          • L Laji59

            Thanks alot. it worked Now I want to convert this code to hex. How can I do it?

            Hello Friends

            A Offline
            A Offline
            Anthony Mushrow
            wrote on last edited by
            #5

            Convert it to int like Guffa said, then display it as hex. To display an int as hex i think you can use .ToString('X');

            My current favourite word is: Nipple!

            -SK Genius

            Game Programming articles start -here[^]-

            D 1 Reply Last reply
            0
            • G Guffa

              Characters are unicode, so you can just convert it to int: int code = (int)'њ';

              Despite everything, the person most likely to be fooling you next is yourself.

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              It is probably better to use: char.ConvertToUtf32(string, int)

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              H 1 Reply Last reply
              0
              • A Anthony Mushrow

                Convert it to int like Guffa said, then display it as hex. To display an int as hex i think you can use .ToString('X');

                My current favourite word is: Nipple!

                -SK Genius

                Game Programming articles start -here[^]-

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                SK Genius wrote:

                .ToString('X');

                That works fine - I prefer Convert.ToString(value, base) as you don't have to remember the silly string formats and you can specify base 2, 8, 10 or 16 so is more flexible. :-D

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Expect everything to be hard and then enjoy the things that come easy. (code-frog)

                1 Reply Last reply
                0
                • L leppie

                  It is probably better to use: char.ConvertToUtf32(string, int)

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                  H Offline
                  H Offline
                  Harvey Saayman
                  wrote on last edited by
                  #8

                  but why? i also usually cast the char to int to get its unicode value

                  Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

                  you.suck = (you.passion != Programming)

                  L 1 Reply Last reply
                  0
                  • H Harvey Saayman

                    but why? i also usually cast the char to int to get its unicode value

                    Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

                    you.suck = (you.passion != Programming)

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    Harvey Saayman wrote:

                    but why?

                    Because .NET has Unicode surrogate pairs, meaning sometimes it takes 2 combined characters to form a complete Unicode code point.

                    xacc.ide - now with TabsToSpaces support
                    IronScheme - 1.0 alpha 4a out now (29 May 2008)

                    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