DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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!

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links