|
-
Dec 2nd, 2008, 07:09 PM
#1
Thread Starter
Hyperactive Member
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?
-
Dec 3rd, 2008, 01:04 AM
#2
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
.....
-
Dec 3rd, 2008, 07:51 AM
#3
Thread Starter
Hyperactive Member
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
-
Dec 3rd, 2008, 12:10 PM
#4
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.
-
Dec 3rd, 2008, 12:22 PM
#5
Thread Starter
Hyperactive Member
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?
-
Dec 3rd, 2008, 05:53 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|