SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    case dependancy trouble with InStr() and mid()

    Hi there,
    I'm having some trouble with an error that is thrown when I use InStr() and Mid() with a database search query.

    In point form:


    1. I am retrieving an array strings from my database where the query is case insensitive. This is good

    2. Then I locate the keyword in the string using InStr() which is case sensitive.
      This is not desireable as it doesn't recognize all instances of the keyword.

    3. I use the Mid() function to give me a portion of the string starting at the location provided by InStr() which is sometimes the number zero which in turn throws the error. This is bad!
    I can do some workarounds with the replace() function but I'm open to any other suggestions.

    Thanks,
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Ok the solution is pretty simple.

    In case anyone else runs into this trouble, use the comparetype option of the InStr() function. If you use it you also have to tell InStr() where to start. It goes like this:

    InStr(start, string, keyword, comparetype)

    x = InStr(1, copy, keyword, 1) 'For case insensitivity
    x = InStr(copy, keyword) 'For case sensitive

    Cheers,
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •