Wrox Programmer Forums
|
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
 
Old October 3rd, 2004, 03:28 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default 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.

 
Old October 4th, 2004, 09:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

It maybe how you are finding and replacing.. Could you post any code?

Brian
 
Old October 4th, 2004, 01:02 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
 
Old October 4th, 2004, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Try removing the bolded code in several places:

strReplaced= strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPo sition-lngStartingPosition) & "" & mid(strSearchWithin,lngFoundPosition,len(strSearch For)) & ""

Brian
 
Old October 4th, 2004, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Also, you may find it easier using replace() method... just a thought.

Brian
 
Old October 4th, 2004, 07:07 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.


 
Old October 5th, 2004, 08:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML to XML transform (Simplified) nmahesh567 XSLT 2 March 24th, 2007 07:57 AM
Problem with highlighting text in a combo box Kabel69 Access 5 October 18th, 2006 08:51 AM
I have another highlighting problem. gilgalbiblewheel Classic ASP Databases 2 July 20th, 2005 02:02 PM
Highlighting in a datalist olambe Classic ASP Components 3 August 23rd, 2004 06:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.