Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 25th, 2006, 11:00 AM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default 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="<b>,<b>,<b>,<b>,<b>,<b>"
strAft="</b>"
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
Martial Law 9/11 Rise of the Police State is now available! Visit our Martial Law movie section for complete info (click here), or order now by clicking the button below or by calling 888-253-3139
http://www.infowars.com/martial_law_911.htm
Reply With Quote
  #2 (permalink)  
Old January 25th, 2006, 09:37 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

What do you mean by highlite?

When the page is rendered make the text appear different?
If so in what way, I am not aware of any highlite html tag.



Wind is your friend
Matt
Reply With Quote
  #3 (permalink)  
Old January 25th, 2006, 10:15 PM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.

Martial Law 9/11 Rise of the Police State is now available! Visit our Martial Law movie section for complete info (click here), or order now by clicking the button below or by calling 888-253-3139
http://www.infowars.com/martial_law_911.htm
Reply With Quote
  #4 (permalink)  
Old January 25th, 2006, 10:22 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;Let's say I'm looking for dog and homework in a textbox
Your objective is to write this highlited text to:
1..The screen as page copy
2..A <textarea>
3..A <input type=text>

Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old January 26th, 2006, 04:25 PM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't understand what you're suggesting.

Martial Law 9/11 Rise of the Police State is now available! Visit our Martial Law movie section for complete info (click here), or order now by clicking the button below or by calling 888-253-3139
http://www.infowars.com/martial_law_911.htm
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using the split function jd_erd Access 2 May 7th, 2007 09:59 PM
split function MunishBhatia ASP.NET 2.0 Professional 4 May 1st, 2007 10:05 AM
Select or Highlight Text ~Bean~ General .NET 0 November 9th, 2005 12:31 PM
using 'Split' function p_gauri7 Crystal Reports 0 March 11th, 2005 01:02 PM
Split function Beulah ASP.NET 1.0 and 1.1 Basics 1 September 12th, 2003 09:14 AM



All times are GMT -4. The time now is 12:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.