#1 (permalink)  
Old 01-25-2006, 09:37 AM
Registered User
 
Join Date: Jul 2004
Posts: 247
How do I highlight a split function text?

How do I highlight a split function text?
Code:
dim strKeywords, strText, strFore, strAft, bolInComplete
dim Text1, Text2, Text3, Text4, Text5, Text6
dim keywordarray, counter

Text1=Request("Keyword")
Text2=Request("Keywordb")
Text3=Request("Keywordc")
Text4=Request("Keywordd")
Text5=Request("Keyworde")
Text6=Request("Keywordf")

IF Text1<>"" THEN

       keywordarray = split(Text1," ")
        StrKeywords = StrKeywords & keywordarray(0)
        for counter=1 to ubound(keywordarray)
            StrKeywords = StrKeywords & " " & keywordarray(counter)
        next

response.write StrKeywords
'StrKeywords = StrKeywords & Text1
END IF

IF Text2<>"" THEN
IF StrKeywords<>"" THEN
StrKeywords =StrKeywords&","&Text2
ELSE
StrKeywords = Text2
END IF
END IF
IF Text3<>"" THEN
IF StrKeywords<>"" THEN
StrKeywords =StrKeywords&","&Text3
ELSE
StrKeywords = Text3
END IF
END IF
IF Text4<>"" THEN
IF StrKeywords<>"" THEN
StrKeywords =StrKeywords&","&Text4
ELSE
StrKeywords = Text4
END IF
END IF
IF Text5<>"" THEN
IF StrKeywords<>"" THEN
StrKeywords =StrKeywords&","&Text5
ELSE
StrKeywords = Text5
END IF
END IF
IF Text6<>"" THEN
IF StrKeywords<>"" THEN
StrKeywords =StrKeywords&","&Text6
ELSE
StrKeywords = Text6
END IF
END IF

strFore="<font color=red><b>,<font color=blue><b>,<font color=green><b>,<font color=orange><b>,<font color=purple><b>,<font color=aqua><b>"
strAft="</b></font>"
bolInComplete=true
Do until RS.eof
strText =rs("text_data")

strText=HighlightKeywords(strText,strKeywords, strFore, strAft,bolInComplete)
Response.Write "<sup>" & rs("verse") & "</sup>" & strText & "</br>"

rs.movenext

Loop
else
response.write "No verses found"
End If

Function HighlightKeywords(byVal strText, byRef strKeywords, byRef strFore, byRef strAft, byVal bolInComplete)

' Dim the variables.
dim arrKeywords
dim strPattern, strReplace
dim i
dim arrstrFore
' Split the list of keywords into an array for easy iteration.
arrKeywords = Split(strKeywords,",")
arrstrFore=Split(strFore,",")

' Loop through the array of keywords and build the strings needed for the highlighting.
For i=0 to UBound(arrKeywords,1)
' Build the pattern string. Basically what we are saying is:
' Find all instances of this word that are distinct words not in pointed brackets.

' If we are not to find incomplete words then use the rigid pattern.
If Not bolInComplete Then
strPattern ="(?!<)\b(" & arrKeywords(i) &")\b(?!>)"
' Else allow for characters following the keyword before the word break.
Else
strPattern ="(?!<)\b(\w*" & arrKeywords(i) &"\w*)\b(?!>)"
End If


' Build the replace string. This tells the regexp what to replace the instances found
' with. We use the $1 to say: Use the value that was there. This is good for use when
' you don't want to change the case of the existing word.
strReplace = arrstrFore(i) & "$1" & strAft


' Call the helper routine.
strText = Highlight(strText,strPattern,strReplace,True)

'response.write arrstrFore(i)
'response.write arrKeywords(i)

Next'i'

' Return the newly formatted string.
HighlightKeywords = strText
End Function

Function Highlight(byVal strText, byRef strPattern, byRef strReplace,byRef bolIgnoreCase)

' Dim the Variables
dim mobjRegExp
dim i

' Initialize the Regular Expressions Object.
Set mobjRegExp = New RegExp

' Set it to find all matches.
mobjRegExp.Global = True

' This parameter tells RegExp if it should be case sensitive or insensitive.
' This is a parameter that should be specified by the calling function.
mobjRegExp.IgnoreCase = bolIgnoreCase

' The pattern to find. This is the most difficult part of using RegExps.
mobjRegExp.Pattern = strPattern

' Call the replace method of the RegExp object. This will do all the work.
strText = mobjRegExp.Replace(strText,strReplace)

' Kill the object.
Set mobjRegExp = Nothing

' Return the newly formatted string.
Highlight = strText
End Function
Reply With Quote

  #2 (permalink)  
Old 01-28-2006, 10:44 AM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
I don't understand the question.
Reply With Quote
  #3 (permalink)  
Old 01-31-2006, 11:40 AM
Registered User
 
Join Date: Jul 2004
Posts: 247
What I meant was that, what I'm looking for is how to highlight words that don't appear side-by-side. Let's say I'm looking for dog and homework in a textbox: "dog homework". ASP splits by split(keyword," ").

I need to highlight like this "the dog ate my homework"

But I don't want to drift away from the present coding except for my attempt of highlighting which was in my previous post above in red.
Reply With Quote
  #4 (permalink)  
Old 01-31-2006, 12:49 PM
Deadeye's Avatar
Moderator
 
Join Date: Aug 2005
Location: San Diego, CA
Posts: 274
Send a message via MSN to Deadeye
afaik a regular text box cant do rich text formatting. I know there are AJAX scripts that can do rich text formating like you want. You will probably need to look farther into this.

*EDIT* misspelled AJAX

Last edited by Deadeye; 01-31-2006 at 01:29 PM.
Reply With Quote
  #5 (permalink)  
Old 01-31-2006, 01:08 PM
Registered User
 
Join Date: Jul 2004
Posts: 247
Can that mix with ASP like it does with VBScript?
Reply With Quote
  #6 (permalink)  
Old 01-31-2006, 01:29 PM
Deadeye's Avatar
Moderator
 
Join Date: Aug 2005
Location: San Diego, CA
Posts: 274
Send a message via MSN to Deadeye
we use it here at my work, and afaik yes
Reply With Quote
  #7 (permalink)  
Old 01-31-2006, 04:15 PM
Registered User
 
Join Date: Jul 2004
Posts: 247
what's afaik?
Reply With Quote
  #8 (permalink)  
Old 01-31-2006, 05:12 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,437
Quote:
Originally Posted by gilgalbiblewhee
what's afaik?
afaik = as far as i know
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
controlling the size of an image with text over it bobs world Graphics and Flash 9 02-25-2006 12:26 PM
jscript: error sending data from page to function weirdlNet Programming and Scripting 5 09-16-2005 06:34 AM
Form and javascript function help - illiterate on this ruthann Programming and Scripting 1 09-11-2005 10:52 AM
Flash: Text - Linear Gradient Leprakawn Graphics and Flash 2 07-07-2005 02:47 AM
Help with copy function - code illiterate here :) ruthann Programming and Scripting 2 07-06-2005 12:43 AM


All times are GMT -5. The time now is 07:03 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter