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 unicode to int in C#?

how to convert unicode to int in C#?

Scheduled Pinned Locked Moved C#
tutorialcsharpquestion
6 Posts 3 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.
  • O Offline
    O Offline
    OmarLodhi
    wrote on last edited by
    #1

    Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi

    V W 2 Replies Last reply
    0
    • O OmarLodhi

      Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Posting the relevant code sample would be helpful. Also, you can try Int32.Parse().

      Cheers, Vikram.


      The cold will freeze our stares We won't care...

      1 Reply Last reply
      0
      • O OmarLodhi

        Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi

        W Offline
        W Offline
        Wayne Phipps
        wrote on last edited by
        #3

        How many characters in the string? Maybe thats the problem? Perhaps you need to ittereate through each character of the string in turn, something like:

        foreach( char character in unicodeString )
        {
             int charValue = Convert.ToInt32( character );
        }
        

        Just an idea. If your still stuck, you should post some of your code.

        Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog

        O 1 Reply Last reply
        0
        • W Wayne Phipps

          How many characters in the string? Maybe thats the problem? Perhaps you need to ittereate through each character of the string in turn, something like:

          foreach( char character in unicodeString )
          {
               int charValue = Convert.ToInt32( character );
          }
          

          Just an idea. If your still stuck, you should post some of your code.

          Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog

          O Offline
          O Offline
          OmarLodhi
          wrote on last edited by
          #4

          Hi, i have to convert a unicode string to its hex equilent. i have converted this from a VB6 code that uses AscW() method to convert unicode to a integer value and then to Hex value. Here is code String strSrc="جمل هندسة في الدنيا أن تبني جسرا من الأمل على بحر من اليأس.."; strResult = ""; for (int i = 0; i < strSrc.Length; i++) { try { //tried this one get exception //nVal = Int32.Parse(strSrc.Substring(i, 4)); //tried also statement below also get exception nVal = Convert.ToInt32(strSrc.Substring(i, 4)); strHex = Convert.ToString(nVal, 16); strResult += strHex; } catch (FormatException e) { ; } } Exceptoin error string is "Input was not in correct format" Thanks and Regards, Omar

          V 1 Reply Last reply
          0
          • O OmarLodhi

            Hi, i have to convert a unicode string to its hex equilent. i have converted this from a VB6 code that uses AscW() method to convert unicode to a integer value and then to Hex value. Here is code String strSrc="جمل هندسة في الدنيا أن تبني جسرا من الأمل على بحر من اليأس.."; strResult = ""; for (int i = 0; i < strSrc.Length; i++) { try { //tried this one get exception //nVal = Int32.Parse(strSrc.Substring(i, 4)); //tried also statement below also get exception nVal = Convert.ToInt32(strSrc.Substring(i, 4)); strHex = Convert.ToString(nVal, 16); strResult += strHex; } catch (FormatException e) { ; } } Exceptoin error string is "Input was not in correct format" Thanks and Regards, Omar

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            Sorry, mate; I don't know any Arabic, so I have no idea if the string you have is a valid numeric string. If what you have is indeed a VALID numeric string in Arabic, perhaps the problem is the locale/culture settings. Int32.Parse() and Convert.ToInt32() both have various overloads - why don't you check them out? Pay special attention to the ones that take a CultureInfo parameter. Also, given Arabic is an RTL language, are you sure Substring() is returning the correct substring?

            Cheers, Vikram.


            The cold will freeze our stares We won't care...

            O 1 Reply Last reply
            0
            • V Vikram A Punathambekar

              Sorry, mate; I don't know any Arabic, so I have no idea if the string you have is a valid numeric string. If what you have is indeed a VALID numeric string in Arabic, perhaps the problem is the locale/culture settings. Int32.Parse() and Convert.ToInt32() both have various overloads - why don't you check them out? Pay special attention to the ones that take a CultureInfo parameter. Also, given Arabic is an RTL language, are you sure Substring() is returning the correct substring?

              Cheers, Vikram.


              The cold will freeze our stares We won't care...

              O Offline
              O Offline
              OmarLodhi
              wrote on last edited by
              #6

              Hi, i think RTL is only for displaying data. in case of string storage it is stored just same as normal string. this code is working in VBA that reads unicode converts unicode string to hex format. do you know any method equivalent to VB method AscW for getting code of any unicode character. Thanks, Omar

              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