VB.NET App: How to convert Unicode String to Integer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaskar
    New Member
    • Nov 2007
    • 5

    VB.NET App: How to convert Unicode String to Integer?

    I have got one problem in VB.NET 2005 using unicode
    I want to add two numbers in vb.net 2005 through UNICODE
    I didn't know how to convert UNICODE string to integer.

    I hope you can solve my problem
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Can you post what you have tried so far.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      int.parse() has overloads that might be able to help you with a unicode string?

      Comment

      • vaskar
        New Member
        • Nov 2007
        • 5

        #4
        Originally posted by debasisdas
        Can you post what you have tried so far.
        I want to add two NepaliUnicode number as
        [code=vbnet]
        Dim a as string=me.textb ox1.text
        dim b as string=me.textb ox2.text
        dim c as integer=val(a+b )
        [/code]
        Above statement throw exception "Input string was not in correct format" Format Exception was unhandled

        I have done above coding through this also:
        [code=vbnet]
        Dim a as string=Integer. Parse(me.textbo x1.text)
        [/code]
        Above statement throw exception "Input string was not in correct format" Format Exception was unhandled

        if you have any idea to convert string to integer but the string is in numeric type unicode.

        I could not find solution for my problem so give me best idea.

        Comment

        • vaskar
          New Member
          • Nov 2007
          • 5

          #5
          Originally posted by Plater
          int.parse() has overloads that might be able to help you with a unicode string?
          Hi Plater


          I have done as per you say but this also throw exception:
          [code=vbnet]
          Dim a as string=Integer. Parse(me.textbo x1.text)
          [code]
          Above statement throw exception "Input string was not in correct format" Format Exception was unhandled

          if you have any idea to convert string to integer but the string is in numeric type unicode.

          thank you

          Comment

          • mzmishra
            Recognized Expert Contributor
            • Aug 2007
            • 390

            #6
            try this way
            [code=vbnet]
            Dim myBytes As Byte() = System.Text.Enc oding.Unicode.G etBytes(textbox 1.text)

            Dim myChars as Char() = System.Text.Enc oding.Unicode.G etChars(myBytes )
            Dim myString as String = New String(myChars)[/code]


            Then convert the string to integer

            Comment

            • vaskar
              New Member
              • Nov 2007
              • 5

              #7
              Originally posted by mzmishra
              try this way
              Dim myBytes As Byte() = System.Text.Enc oding.Unicode.G etBytes(textbox 1.text)

              Dim myChars as Char() = System.Text.Enc oding.Unicode.G etChars(myBytes )
              Dim myString as String = New String(myChars)


              Then convert the string to integer
              Thank You mzmishra
              I will try it.

              Comment

              • vaskar
                New Member
                • Nov 2007
                • 5

                #8
                Originally posted by mzmishra
                try this way
                Dim myBytes As Byte() = System.Text.Enc oding.Unicode.G etBytes(textbox 1.text)

                Dim myChars as Char() = System.Text.Enc oding.Unicode.G etChars(myBytes )
                Dim myString as String = New String(myChars)


                Then convert the string to integer
                mzmishra

                I had try as per you say.
                when I convert MyString to integer Exception arises
                that is "Input String was not in correct format" but the string which I press is string representation of numeric type of unicode that is 1 in US-eng and "१" in Nepali Unicode.

                my line of code is

                Dim myNum as Integer =Integer.parse( myString)

                If you have any idea. I will be thanks for your help.

                Comment

                • mzmishra
                  Recognized Expert Contributor
                  • Aug 2007
                  • 390

                  #9
                  Hmm.
                  Not sure then.Probably someone else can give some idea

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    If I had to guess, I would think you would need to use the overloads for int.parse() that use the NumberFormatInf o object.
                    It can be assigned a culture.
                    You may also need to do things like allow decimal and thousands seperators.

                    What is the string you are trying to conver to integer?
                    Even as a unicode string, they still need to represent numbers, so random symbols won't work.

                    int.parse("123j jk"); will throw the same error, regardless of being a unicode or ascii string.

                    Comment

                    Working...