Highlight Text based on certain criteria

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?
 
A

Axel Dahmen

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
 
A

Axel Dahmen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top