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. Getting ASCII value for Characters?

Getting ASCII value for Characters?

Scheduled Pinned Locked Moved C#
comquestion
8 Posts 5 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.
  • M Offline
    M Offline
    murali_utr
    wrote on last edited by
    #1

    Need Convert character to ascii value. For character "‚" ascii value is 130 but I got 8218. string is "õí‚è‹". for (int i = 0; i < rtfSource.Text.Length; i++) { rtfSource.Select(i, 1); strTemp = rtfSource.SelectedText.ToString(); strChar = strTemp.Substring(0, 1); iCode = (int)strChar[0]; }

    Have A Nice Day! Murali.M Blog

    B L 2 Replies Last reply
    0
    • M murali_utr

      Need Convert character to ascii value. For character "‚" ascii value is 130 but I got 8218. string is "õí‚è‹". for (int i = 0; i < rtfSource.Text.Length; i++) { rtfSource.Select(i, 1); strTemp = rtfSource.SelectedText.ToString(); strChar = strTemp.Substring(0, 1); iCode = (int)strChar[0]; }

      Have A Nice Day! Murali.M Blog

      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2

      What you have is not an ASCII coded character, and it is not a "comma;" it is Unicode, specifically the single low-9 quotation mark: [^]. So, if you must work with Unicode character sets, you should plan to forget about using plain-old ASCII. There are over 100k Unicode characters, and only 128 in ASCII. While you can access an ASCII "mapping" via the Encoding Class:

      byte[] unicode = Encoding.Unicode.GetBytes("õí‚è‹");

      string Ascii = Encoding.ASCII.GetString(unicode);

      The result of this would be: "?\0?\0 ?\09" : the "?" indicates result is unknown for a given character.

      «I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

      M 1 Reply Last reply
      0
      • M murali_utr

        Need Convert character to ascii value. For character "‚" ascii value is 130 but I got 8218. string is "õí‚è‹". for (int i = 0; i < rtfSource.Text.Length; i++) { rtfSource.Select(i, 1); strTemp = rtfSource.SelectedText.ToString(); strChar = strTemp.Substring(0, 1); iCode = (int)strChar[0]; }

        Have A Nice Day! Murali.M Blog

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

        murali_utr wrote:

        but I got 8218

        Which is correct, it's a Unicode character.

        1 Reply Last reply
        0
        • B BillWoodruff

          What you have is not an ASCII coded character, and it is not a "comma;" it is Unicode, specifically the single low-9 quotation mark: [^]. So, if you must work with Unicode character sets, you should plan to forget about using plain-old ASCII. There are over 100k Unicode characters, and only 128 in ASCII. While you can access an ASCII "mapping" via the Encoding Class:

          byte[] unicode = Encoding.Unicode.GetBytes("õí‚è‹");

          string Ascii = Encoding.ASCII.GetString(unicode);

          The result of this would be: "?\0?\0 ?\09" : the "?" indicates result is unknown for a given character.

          «I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

          M Offline
          M Offline
          murali_utr
          wrote on last edited by
          #4

          its not comma, and ttf font not Unicode font. Alt+0130 is it value. How can I get the ascii value 130. third character in the string.

          Have A Nice Day! Murali.M Blog

          U OriginalGriffO 2 Replies Last reply
          0
          • M murali_utr

            its not comma, and ttf font not Unicode font. Alt+0130 is it value. How can I get the ascii value 130. third character in the string.

            Have A Nice Day! Murali.M Blog

            U Offline
            U Offline
            User 12121758
            wrote on last edited by
            #5

            Alt+130 would be é not è (which you wrote in your question). è would be Alt+138. But those are both not ASCII since ASCII has only 128 Symbols. So what exactly do you want to do? Convert the third character (which would be ",") or the è ?

            M 1 Reply Last reply
            0
            • U User 12121758

              Alt+130 would be é not è (which you wrote in your question). è would be Alt+138. But those are both not ASCII since ASCII has only 128 Symbols. So what exactly do you want to do? Convert the third character (which would be ",") or the è ?

              M Offline
              M Offline
              murali_utr
              wrote on last edited by
              #6

              I want to mapping characters by based on ASCII Value.

              Have A Nice Day! Murali.M Blog

              L 1 Reply Last reply
              0
              • M murali_utr

                its not comma, and ttf font not Unicode font. Alt+0130 is it value. How can I get the ascii value 130. third character in the string.

                Have A Nice Day! Murali.M Blog

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

                Unicode isn't a font - it's a character set which can be displayed on a suitable context using a font to "describe" the exact shape to be drawn for each character. ASCII is a different (and much smaller, more limited) character set - which can also be displayed using a font, but the number of different shapes that can be drawn is far fewer. Fonts are things like Arial, Times New Roman, Verdana, Wingdings - they are ways to display the same character from a character set differently. And the third character in the string "õí‚è‹" is ','. The character at index 3 is 'è' which exists in the Extended ASCII character set (which has 256 characters) but doesn't exist in the standard 128 character ASCII set.

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "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

                1 Reply Last reply
                0
                • M murali_utr

                  I want to mapping characters by based on ASCII Value.

                  Have A Nice Day! Murali.M Blog

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

                  Then you need to convert the Unicode characters in your data to their ASCII equivalents first. But be aware that you may lose some of them completely if they do not map to an ASCII character.

                  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