PDA

View Full Version : .net: Highlight Multiple Words in a search


david7777
02-16-2005, 09:03 AM
I am trying to build a server side function to highlight multiple words in search results...
What i need is a function which takes in the text to search, the text to find, and the text to add before and after the found text.

For reference:
Text to search: "This is some text to search..."

So if I try to find "some", the function module might return, "This is <b>some</b> text to search..."

I have that working fine. Now if i want to find "some sear", the function would return "This is <b>some</b> text to <b>sear</b>ch..."

That also works fine.

If i want to find "s", then the function returns, "Thi<b>s</b> i<b>s</b> <b>s</b>ome text to <b>s</b>earch..."

My problem is if i want to find "s b", then the function returns, "Thi<<b>b</b>>s</<b>b</b>> i<<b>b</b>>s</<b>b</b>> <<b>b</b>>s</<b>b</b>>ome text to <<b>b</b>>s</<b>b</b>>earch..."

This is obviously due to using a simple function recursivly, resulting in unexpected results.

The function must not change the case of the text it returns - I think the best option would be to use regular expressions.

Any suggestions?