Results 1 to 7 of 7

Thread: searching a string

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    searching a string

    forgot the function to search for a string within a string...how do i do that again?

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    InStr

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    so i have 2 strings, i want to find choice in StringCompare

    If InStr(1, choice, StringComp, vbBinaryCompare) <> True Then

    so i'll do that? that will tell me if its not found?

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    The Instr() function returns a Long!
    And, reverse the Search and String.

    So, try:
    VB Code:
    1. If InStr(1, StringComp, choice , vbBinaryCompare) <> 0 Then ' Match found




    Bruce.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    what if i don't know where it starts?

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    If you use the 'comparison' argument, you have to include a 'start'.


    In that example, it starts at the front end of the string, and will return the first match position.

    If you need repeditive search, then return the Instr position and use that next time around as the 'start' position.


    (Also see InstrRev (VB6))




    Bruce.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    never mind, i kind of went nuts with a for loop thanks guys! im rusty with my vb, its sure been a while!

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