Parsing a string starting from the Right


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Parsing a string starting from the Right

  1. #1
    Join Date
    Dec 2003
    Posts
    23

    Parsing a string starting from the Right

    Hi,

    I have a string where I need to start from the right side and find the first non numeric character and then parse out the numerics.

    Example:


    abcd12345

    I would like 12345.

    123xcfg!987

    I would like 987.

    @#$%234*

    ! would like an empty string.

    this is what I am currently doing:

    index = 1

    Do
    str = Mid$(strString, index, 1)

    Select Case str

    Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
    strAccNumber = Mid$(strString, index, Len(strString))
    Exit Do
    Case Else
    index = index + 1
    End Select

    Loop

    but the problem with this code is that when I get string like:


    5^&*%2345

    It returns a string of 5^&*%2345.

    Instead of using mid$ how can I start from the right (the last character in the string)?

    Thanks,

  2. #2
    Join Date
    Dec 2003
    Posts
    52
    Try something like:

    index = len(strString)

    Do
    str = mid(strString, index, 1)
    if (isnumeric(str) = false) then
    str = MID(strString, index + 1)
    exit do
    else
    index = index - 1
    end if
    loop until index = 0

    This is purely "air code", but I think it will work.

  3. #3
    Join Date
    Dec 2003
    Posts
    23
    Hi,

    It did work. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center