|
-
Aug 17th, 2001, 06:04 AM
#1
Thread Starter
New Member
detecting alphanumeric content in strings
Curious if anyone knows a good way to detect if there are any characters (those falling in the range of ASCII 65-122) in a string that would ordinarily be holding numerals. Sounds ridiculous but let me explain...
I have a situation where I'm receiving quick bursts of packet-level data in the form of a Windows Media Player ScriptEvent. It *ordinarily* is a number that I must deal with, an 8-digit number usually led by 3 zeros, forcing me to handle it as a string to keep those leading zeros from being stripped away. Example: 00071856. It has to be a string equal to "00071856," and not a long because naturally then I end up getting "71856," and the lack of the leading zeros yields the wrong results once that number ends up where it needs to (to further clarify, that number is the middle piece in a URL, where "http://pathtosite.com/" & ThatNumber & ".xml" brings me to an XML doc I need to read, so if the valid document is http://pathtosite.com/00071856.xml, treating that number as a long would take me to http://pathtosite.com/71856.xml, a page that doesn't exist).
Unfortunately there are inconsistencies in the data that comes, and every once in a while the engine pushing it out accidentally drops a few letters in there, so I end up getting something like "00IAAL856," which screws everything up, as all of the final XML docs I'm trying to reach are numerically named.
What I need to do is be able to detect those scenarios before I get that data and send to where it needs to go. As it is written right now, I just have a vanilla On Error in the procedure where that data ends up, but I don't like how sloppy that is.
So does anyone know a good way of testing a string "00071856" to make sure there aren't any alpha characters in it? I've come up with a few hacks, all generally lacking in the desired consistency/stability.
Any help is greatly appreciated.
-
Aug 17th, 2001, 06:09 AM
#2
Registered User
long question, short answer 
Isnumeric() will do the job
Debug.Print IsNumeric("00IAAL856")
Debug.Print IsNumeric("00071856")
-
Aug 17th, 2001, 06:10 AM
#3
PowerPoster
Hi
I guess u could just use the IsNumeric function since u want only numbers
Debug.print IsNumeric("1234") returns True
Regards
Stuart
-
Aug 17th, 2001, 06:13 AM
#4
Lively Member
try this
private function stringcheck(mystring as string) as boolean
dim i as integer
dim intchar as integer
stringcheck = true
for i = 0 to len (mystring)
intchar = asc(mid$(mystring,i,1))
if (intchar > 64 and intchar<91) or (intchar>96 and intchar<123) then
stringcheck = false
exit for
end if
next i
end function
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
|
Click Here to Expand Forum to Full Width
|