Problem in Strings in ASP.NET(vb)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidson1
    New Member
    • Feb 2008
    • 144

    Problem in Strings in ASP.NET(vb)

    Hai friends...
    In our Organization... we have regno...like 06AKK012 06AK012 06A012

    Now my question...when ever user enter regno.. I want to Extract..till last alphabetic charcter of regno...
    for example..

    06AKK012 => 06AKK
    06AK012 => 06AK
    06A012 => 06A


    is there any option.....
    give me coding what we write.... in webform.aspx.vb ....
    Thank u...
    Davidson..
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well if you treated the string as a char[] (which it is in a way) and start sliding to the left, using .IsLetter().
    As soon as it says yes, set a boolean value. When it finds a "non letter" after the boolean has been set (so you know it has made it through the alphabetic characters). you can exit out of the loop and return the index that you were on in the char[].

    Comment

    • davidson1
      New Member
      • Feb 2008
      • 144

      #3
      Thank u plater..

      can u give me coding...in asp.net(vb language)

      what we write in webform.aspx.vb

      Davidson.......

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by davidson1
        Thank u plater..

        can u give me coding...in asp.net(vb language)

        what we write in webform.aspx.vb

        Davidson.......
        You could go clever and use the Split function with a regex.

        Comment

        • davidson1
          New Member
          • Feb 2008
          • 144

          #5
          Thank u r035...

          if u give sample coding....it will be understandable. ...

          please...

          Comment

          • kunal pawar
            Contributor
            • Oct 2007
            • 297

            #6
            U can convert string to character array and then check character is letter.
            like this
            Dim c() As Char
            Dim i,flg,pos as Int16
            flg=1
            c = str.ToCharArray
            for i=0 to c.length
            if flg=2 and c(i).Isnumaric( ) then
            pos = i
            exit for
            end if
            if c(i).IsLetter() then
            flg=2
            end if

            next
            substring the string upto pos

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              if you have a string, you can refer to it just like an array, no need to call .ToCharArray() for it.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                How about
                [CODE=vbnet]
                Imports System.Text.Reg ularExpressions
                Module Module1
                Sub Main()
                Dim regNo As String
                regNo = "06AK012"
                Dim r As Regex
                r = New Regex("\D")
                Dim s As String() = Nothing
                s = r.Split(regNo)
                Dim t As String
                t = regNo.Substring (regNo.IndexOf( s(s.Length - 1)))
                Dim v As String
                v = regNo.Substring (0, regNo.IndexOf(t ))
                MsgBox(v)
                End Sub
                End Module[/CODE]

                Washes mouth for writing VB

                Comment

                Working...