Highlighting text in a string.

Results 1 to 4 of 4

Thread: Highlighting text in a string.

  1. #1
    delita Guest

    Default Highlighting text in a string.

    I&#039m working on a search program, and what I want it to do, is once the headers are returned, replace the search string with the search string and bold tags around each word. They can search on as many words as they want to it would have to be able to do this.<BR><BR>Right now I&#039m just using a replace() command, but the only problem is that it&#039s case sensitive, so it ignores half the results. And I also want it to keep the original case when it replaces it.<BR><BR>Is there any easy way to do this? (Or complex, as long as it works)<BR><BR>jp

  2. #2
    Join Date
    Dec 1969

    Default RE: Highlighting text in a string.

    you can do <BR>instr in loop and every time you find it split it inserting <BR>your tags inside

  3. #3
    KPW Guest

    Default RE: Highlighting text in a string.

    The Replace function does not have to be case sensitive. Check out the VBScript reference link on the left and look for the Replace function. (Incidentally, you will want to use the vbTextCompare option.)<BR><BR>HTH

  4. #4
    delita Guest

    Default I figured it out on my own :)

    &#039function to highlight the search values in the result string<BR>public function highlight(strSearchIn, searchWord)<BR> searchWord = lcase(searchWord)<BR> for y = 1 to (len(strSearchIn) - len(searchWord) + 1)<BR> if mid(lcase(strSearchIn), y, len(searchWord)) = searchWord then<BR> replaceWord = mid(strSearchIn, y, len(searchWord)) highlight = replace(strSearchIn, replaceWord, "&#060;b&#062;" & replaceWord & "&#060;/b&#062;")<BR> end if<BR> next<BR>end function<BR><BR>It carries over the actual string, and the text you want to highlight, then uses mid to search through the string for the value and then uses the location to find the actual value from the string and then replaces it with a highlighted version.<BR><BR>Works like a charm and is quite fast as well (I didn&#039t notice any real slowdown)<BR><BR>jp

Posting Permissions

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