Highlight Text based on certain criteria

  • Thread starter Thread starter Stephajn Craig
  • Start date Start date
S

Stephajn Craig

The senario is that a user fills out a form specifying some keywords they
want to search a knowledgebase for. For each article that comes back, the
words in the article that match their keywords are highlighted. (Much like
Windows Help does)

At serverside, how would I go about handling this?
 
I can't tell you the exact steps, but within your code-behind file, open a HTTP connection and read the HTML file you want to expose. Then write the content to the client almost 1:1 by using "Response.Write();". Before writing the content you have to examine it and add highlighting tags to it, of course.

HTH,
Axel Dahmne
 
If you're using just plain text, it is rather simple:

- Read the whole text into a string variable,
- Search each of the words using string.indexOf() as much as required,
store the indices (+string length) found into a sorted array or anything.
- Go through the array in reverse order and add your tags to the string
at the appropriate places,
- Output the string using Response.Write();

However, it becomes quite complicated if the text contains formatting. In that case I suppose you look for an appropriate control helping you in searching/editing the text portion of the data. There's an IE control providing a HTML-DOM and an XML control (MSXML) providing an XML-DOM.

Axel Dahmen
 
Back
Top