There is something wrong in this. I couldn't figure it out.
I have three: Keyword, Keywordb, Keywordc
I had inserted: strSearchFor, two, three (same function)
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function stringReplace(strSearchWithin,strSearchFor,two,three)
Dim lngStartingPosition
Dim lngFoundPosition
Dim strReplaced
'Set the start position
lngStartingPosition=1
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,three,1)
do while lngFoundPosition > 0
'found
strReplaced=strReplaced & Mid(strSearchWithin,lngStartingPosition,lngFoundPosition-lngStartingPosition) & "<font color='red'>" & "<b>" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & "</b>" & "</font>"
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,three,1)
Loop
stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
End Function
</SCRIPT>
and that you should use 3 different "lngFoundPosition" since you are looking for 3 different strings.
gilgalbiblewhee
10-02-2004, 01:40 PM
Here are what I tripled:
Dim lngStartingPosition
Dim lngStartingTwoPosition
Dim lngStartingThreePosition
Dim lngFoundPosition
Dim lngFoundTwoPosition
Dim lngFoundThreePosition
Dim strReplaced
Dim strTwoReplaced
Dim strThreeReplaced
In this:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function stringReplace(strSearchWithin,strSearchFor,two,three)
Dim lngStartingPosition
Dim lngStartingTwoPosition
Dim lngStartingThreePosition
Dim lngFoundPosition
Dim lngFoundTwoPosition
Dim lngFoundThreePosition
Dim strReplaced
Dim strTwoReplaced
Dim strThreeReplaced
'Set the start position
lngStartingPosition=1
lngStartingTwoPosition=1
lngStartingThreePosition=1
lngFoundPosition=InStr(lngStartingPosition,strSearchWithin,strSearchFor,1)
lngFoundTwoPosition=InStr(lngStartingTwoPosition,strSearchWithin,two,1)
lngFoundThreePosition=InStr(lngStartingThreePosition,strSearchWithin,three,1)
do while lngFoundPosition > 0 AND lngFoundTwoPosition > 0 AND lngFoundThreePosition > 0
'found
Loop
stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
stringTwoReplace=strTwoReplaced & Mid(strSearchWithin,lngStartingTwoPosition) 'catch the last one
stringThreeReplace=strThreeReplaced & Mid(strSearchWithin,lngStartingThreePosition) 'catch the last one
End Function
Two websites said that there is problem in case-ing.
<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) & "<font color='red'>" & mid(strSearchWithin,lngFoundPosition,len(strSearchFor)) & "</font>"
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) & "<font color='blue'>" & mid(strSearchWithin,lngFoundtwoPosition,len(two)) & "</font>"
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>
<font color='red'>ezra</font> <font color='blue'>artaxerxes</font>
<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.
javaNoobie
10-06-2004, 12:13 AM
you will have to re-assign searchWithin to the new searchWithin that contains the highlighted text.
stringReplace=strReplaced & Mid(strSearchWithin,lngStartingPosition) 'catch the last one
strsearchWithin = stringReplace
'Set the start position
lngStartingPosition=1
lngFoundtwoPosition=InStr(lngStartingPosition,strSearchWithin,two,1)
webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved.