0

Visual Studio 2010, Visual Basic.NET

I have a form that loads an html file into a WebBrowser control. The user can then search for a word or phrase inside that html document. I need to pull back the innerHtml because I need to be able to add a span tag to what the user searched for. Very simple stuff. The issue I am running into is, when the user searches for something that has an extra space in it.

Now my problem is if the user searches for "a. Testing", it doesn't find anything. The actual html file has two spaces between a. and Testing instead of just one. The browser control is smart enough to remove this extra space when it displays the html to the user.

I hope this makes sense. Here is my search code.

searchString = txtSearch.Text
textToSearch = wbSearch.Document.Body.InnerHtml

textToSearch = textToSearch.Replace(searchString, "<span style=""background-color:yellow"">" & searchString & "</span>")

wbSearch.Document.Body.InnerHtml = textToSearch

There is also another portion of text that fails if the user searches for it.

Say the user copies and pastes a portion of text into the search textbox, the text that they copy is "testing for services."

Seems simple enough, but the actual html file has "testing for services< /a>." so the search cannot find it because the user string is different from what is in the html.

xRuhRohx
  • 422
  • 1
  • 6
  • 31

1 Answers1

0

This sounds like a good candidate for regular expressions. I have a feeling that you may run into an issue if your HTML contains a non-breaking space searching&nbsp;for&nbsp;services. You may want to do a replace of &nbsp; with a space before doing your RegEx.

How to ignore whitespace in a regular expression subject string?

Community
  • 1
  • 1
InbetweenWeekends
  • 1,405
  • 3
  • 23
  • 28