-
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,
-
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.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks