Results 1 to 6 of 6

Thread: Multiple word search question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Question Multiple word search question

    Hello,

    I need to make a search engine search for multiple words from one command button.

    This line works fine and will find "hello".

    VB6 CODE:
    RTFText2.Find "HELLO", RTFText2.SelStart + 1, Len(RTFText2.TextRTF)

    This is what I want to do.

    RTFText2.Find "HELLO" OR "GOODBYE" OR "OKAY", RTFText2.SelStart + 1, Len(RTFText2.TextRTF)

    How can I do this?
    Thanks,
    GARY

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Multiple word search question

    If your searching text (not a database query) I'd suggest regular expressions or regex. What do you want to do when you find each word?

    if regex.ismatch("HELLO|GOODBYE|OKAY") then
    .....

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Multiple word search question

    Thanks brin351, I have no idea what regex is. Do I have to declare it? I'm not using a database. I want to highlight and bold each word found throughout the whole document, but visit them one at a time.
    Last edited by GARY MICHAEL; Dec 3rd, 2008 at 08:13 AM.
    Thanks,
    GARY

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Multiple word search question

    Regex is 'regular expressions' which is a textual way of defining a pattern that you want. It's a whole world in itself.

    Anyways, the answer to your question 'depends'. You have a textbox and you want to search through it for various words. You can either loop through all the words given to you and search for each one individually or use a regular expression to look for all words. Do a search for regex to learn more about it, it's simple but it's also quite vast. For your purposes you will need to construct the regex string that you then need to run against your text. It will then return an indication to you whether any matches have been found. The exact code to accomplish it depends on what you want to do with this text you find.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Multiple word search question

    Thanks Mendhak,

    Can you post a short code from scratch to search a text box for say, three words and bold them?
    Thanks,
    GARY

  6. #6
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Multiple word search question

    Here is a so called highlight function I've used before. I think I picked it up from www.4guysfromrolla.com some time ago

    Code:
    Function Highlight(Search_Str as String, _
    	                   InputTxt as String, _
    	                   StartTag as String, _
    	                   EndTag as String) As String
    
    	  Dim ResultStr As String 
    	  Return Regex.Replace(InputTxt, "\b(" & Regex.Escape(Search_Str) & ")\b", _
    	           StartTag & "$1" & EndTag, RegExOptions.IgnoreCase)
    	End Function

    It places a html tag of your choice around the search text. It only does 1 word search at a time so you would have to call it for each word or modify it.

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