Results 1 to 4 of 4

Thread: detecting alphanumeric content in strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    New York, NY
    Posts
    6

    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.

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    long question, short answer

    Isnumeric() will do the job

    Debug.Print IsNumeric("00IAAL856")
    Debug.Print IsNumeric("00071856")

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    I guess u could just use the IsNumeric function since u want only numbers

    Debug.print IsNumeric("1234") returns True
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89
    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
  •  



Click Here to Expand Forum to Full Width