Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


highlighting an array of keywords

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,23842
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> highlighting an array of keywords
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 highlighting an array of keywords - 7/20/2005 7:14:35 AM   
  gilgalbiblewheel

 

Posts: 14
Score: 0
Joined: 4/6/2005
From:
Status: offline
[CODE]
<%
strFind = Keyword '"jeSus christ joseph begat"
strText =rs("text_data") '"And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ."
response.write Highlight(strText, strFind)
%>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function Highlight(strText, strFind)
'// Check that at least one search term has been submitted
If Len(strFind) < 1 Then
'// no search term entered. Exit the function
Highlight = "No search term entered"
Exit Function
End If

'// define the colours to be used to highlight search results
Dim strColors : strColors = "#FF0000" ',#008000,#0000FF
'// and split them into an array
Dim arrColors : arrColors = Split(strColors,",")

'// split the search terms into an array
Dim arrFind : arrFind = Split(strFind," ")

'// Initialize the regular expression object to perfom the search
Dim oRegExp, oMatches, sMatch
Set oRegExp = New RegExp
oRegExp.Global = True '// returns all matches to the search term
oRegExp.IgnoreCase = True '// Case insensitive

'// loop through the array of search terms to find matches
Dim i, strHighlight
For i = 0 to UBound(arrFind)
oRegExp.Pattern = arrFind(i) '// sets the search pattern string
Set oMatches = oRegExp.Execute(strText) '// performs the search
for each match in oMatches
'// build the code to be used to highlight results
strHighlight = "<font color='red'><b>" & match.value & "</b></font>" '" & arrColors(i) & "
next
'// then replace matches from the search with the above code
strText = oRegExp.Replace(strText, strHighlight)
Next
'// release the RegExp object
Set oRegExp = Nothing
'// and return the result
Highlight = strText
End Function
</SCRIPT>
[/CODE]

SO I made the changes but whenever I insert the Keyword and rs("text_data")
I get this error:
[QUOTE]
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'Highlight'
/wheelofgod/highlightingz.asp, line 4
[/QUOTE]
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> highlighting an array of keywords Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts