SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text Highlighting issue

    I am doing search application in ASP. I want to highlight the matched text in the search result, for that operation I am using the following function

    Function body

    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

    Function call

    Highlight(text,words(j), "<font color='#FF6600'>", "</font>")

    Here words(j) array will contains all the given search key words

    Its working fine for the single word, to highlight more than one word I am using the following function call

    for j=0 to ubound(words)
    text= Highlight(text,words(j), "<font color='#FF6600'>", "</font>")
    Next

    If I give search word opal its working fine

    Opal-Service


    If I give opa o

    <Font color='#FF6600'>Opa</Font>l-Service


    the problem is it will consider opa and a or two different words so first I will highlight the word using the code

    <font color=#FF6600>opal</font>

    for the second iteration it will highlight the word o, here only the problem arising thats it will find word o in the <font> tag so it will highlight the o in the font and other o.

    Not only for o If I give any of the character in the in the <font color=#FF6600> </font>. it will create the same problem

    if any one knows the function to highlight more than one word in the given string please help me.

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The same function i have used which is given in the above link, but i am facing the probelm in highlighting more than one words.
    Last edited by telic; Jun 8, 2005 at 01:52.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •