 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 3rd, 2004, 03:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
|
|
highlighting. Problem simplified but still there
I'm using the code on:
http://www.aspfree.com/c/a/ASP%20Cod...-by-Meraj-Sami
I want to use two colors on two keywords, one in red, the second in blue.
This is the result:
http://n.1asphost.com/wheelofgod/highlighting.asp
(there is a third color with a third keyword but, never mind that)
The problem is that it's restarting the text once it has found and replaced the keyword in color.
|
|

October 4th, 2004, 09:41 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
It maybe how you are finding and replacing.. Could you post any code?
Brian
|
|

October 4th, 2004, 01:02 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Here is the code:
Code:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function stringReplace(strSearchWithin,strSearchFor,two,three)
Dim lngStartingPosition
Dim lngFoundPosition
Dim lngFoundtwoPosition
Dim lngFoundthreePosition
Dim strReplaced
'Set the start position
lngStartingPosition=1
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
do while lngFoundPosition > 0
'found
strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & ""
lngStartingPosition=lngFoundPosition+len(strSearchFor)
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
Loop
stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
'Set the start position
lngStartingPosition=1
lngFoundtwoPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
do while lngFoundtwoPosition > 0
'found
strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundtwoPosition-lngStartingPosition) & "" & mid(strSearchWithin,lngFoundtwoPosition,len(two)) & ""
lngStartingPosition=lngFoundtwoPosition+len(two)
lngFoundtwoPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
Loop
stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
End Function
</SCRIPT>
<%
OPTION EXPLICIT
Dim strSearchWithin,strSearchFor,two,three
strSearchWithin="Ezra 7:1 Now after these things, in the reign of Artaxerxes king of Persia, Ezra the son of Seraiah, the son of Azariah, the son of Hilkiah, "
strSearchFor="Ezra"
two="Artaxerxes"
three="king"
Response.Write stringReplace(strSearchWithin,strSearchFor,two,three)
%><br><br>
ezra artaxerxes
<br><br>
Original phrase:<br>
Ezra 7:1
Now after these things, in the reign of Artaxerxes king of Persia, Ezra the son of Seraiah, the son of Azariah, the son of Hilkiah,
<br><br>
The problem is that it's restarting the text once it has found and replaced the keyword in color.
|
|

October 4th, 2004, 02:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Try removing the bolded code in several places:
strReplaced= strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPo sition-lngStartingPosition) & "" & mid(strSearchWithin,lngFoundPosition,len(strSearch For)) & ""
Brian
|
|

October 4th, 2004, 02:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Also, you may find it easier using replace() method... just a thought.
Brian
|
|

October 4th, 2004, 07:07 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
|
|
1.Can't I keep the bold?
2.yeah but it doesn't work. I need a non-case-sensitive one.
The code works as it was written. But I needed to make some adjustments for my keyword searches of my text column of my database.
So I need the non-case sensitivity. What I don't understand is why does it restart writing the text when it replaces a keyword? see the url I had posted above.
|
|

October 5th, 2004, 08:13 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
If you do strReplaced = strReplaced & mid(..) it yields:
for example text of: this is some example text
To highlight example, this is the result from the previous:
this is some example text example
What you need to do is something like this:
Code:
intPos = instr(strText, "example")
strWords = "" & mid(strText, intPos, len(strWords)) & ""
strLeft = trim(left(strText, intPos -1))
strRight = trim(right(strText, intPos + len(strText)))
strText = strLeft + strWords + strRight
'Loop again if needed
Once you do strReplaced = strReplaced & it takes the entire string, then appends the result, which is what you were getting.
Brian
|
|
 |