Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - highlight  results problem with replace
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

highlight results problem with replace

 Post Reply Post Reply Page  12>
Author
amisima View Drop Down
Newbie
Newbie


Joined: 09 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote amisima Quote  Post ReplyReply Direct Link To This Post Topic: highlight results problem with replace
    Posted: 23 July 2003 at 8:05am
Hi I am trying to highlight my search results. I have a replace function, when I highlight the search result the rest of my results changes into upper case. This is what my code looks like:

<%if InStr(ucase(rs("EN")),ucase(search_criteria)) <> 0 then %>   
      <td><B>{EN}</B></td>
      <%
      pos=InStr(ucase(rs("EN")),ucase(search_criteria))
      chunk=Mid(rs("EN"),pos,Len(search_criteria))
      MyHighlight=Replace(ucase(rs("EN")), ucase(search_criteria), "<SPAN STYLE=background:#FFFF00>"& chunk &"</SPAN>")
      %>
      <td><b><%Response.Write (MyHighlight)%></b></td><%
    else
      if rs("EN") <> empty then
        %>
        <td><B>{EN}</B></td>
        <td><b><%response.write(rs("EN"))%></b></td><%   
      end if
    end if%>

can anyone help?

Thanks

Amisima
Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2003 at 10:40am

Try this:

<%
If InStr(Ucase(rs("EN")), Ucase(search_criteria)) <> 0 Then
%>   
<td><b>{EN}</b></td>
<%
 pos = InStr(Ucase(rs("EN")), Ucase(search_criteria))
 chunk = Mid(rs("EN"), pos, Len(search_criteria))
 MyHighlight = Replace(rs("EN"), search_criteria, "<SPAN STYLE='background:#FFFF00;'>"& chunk &"</SPAN>", 1, -1, 1)
%>
<td><b><%= MyHighlight %></b></td>
<%
Else
 If rs("EN") <> Empty Then
%>
        <td><b>{EN}</b></td>
        <td><b><%= rs("EN") %></b></td>
<%   
 End If
End If
%>

- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
amisima View Drop Down
Newbie
Newbie


Joined: 09 June 2003
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote amisima Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2003 at 11:07am
I will try that thanks
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2003 at 11:15am
I think this would be a good tutorial in the ASP Tutorials section of WWG. This gets asked about once per month...
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2003 at 12:11pm

There is a better way to do that IMHO. I faced the same problem that it was disturbing the case of your result so I am using the following function:

Function Highlight(strText, strFind, strBefore, strAfter)
 Dim nPos
 Dim nLen
 Dim nLenAll
 
 nLen = Len(strFind)
 nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

 Highlight = strText

 If nLen > 0 And Len(Highlight) > 0 Then
  nPos = InStr(1, Highlight, strFind, 1)
  Do While nPos > 0
   Highlight = Left(Highlight, nPos - 1) & _
    strBefore & Mid(Highlight, nPos, nLen) & strAfter & _
    Mid(Highlight, nPos + nLen)

   nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
  Loop
 End If
End Function

 

Usage example:
itext = Highlight(itext, yoursearchword,"<span style='background:yellow'>", "</span>")

Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2003 at 9:16pm
Just an FYI, when you are using the Replace function in ASP, if you are having probelms with case sensitivity, set the last parameter of the function to 1, that way it will do a textual compare instead of a binary compare, and it doesnt care about case then. For more information on the Replace function, visit: http://www.w3schools.com/vbscript/func_replace.asp
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 24 July 2003 at 7:30am
Tried that Flame, it does not work.
Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 24 July 2003 at 4:18pm
Weird, I've never had a problem with it...
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.