I get web response and use streamreader to obtain the response as a string
my code is
HttpWebResponse response = (HttpWebResponse) request.GetRespons
Well, personally I would use:
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains(...))
{
}
}
Reading the line gives you the data and tells you whether you've reached the end of the stream. I agree with Jeff though - "parsing" HTML by reading it line by line is generally a bad idea. It may be good enough in your specific situation, of course.
This really depends - do you need to know where in the DOM your particular text resides? How large is the input? Will your string ever be split between two lines?
If you are only concerned about the presence of the text and your input is small enough to reside in memory, I'd just read the entire thing in to memory. I'm not sure what the exact algorithm the CLR uses to do string matching, but some of the faster routines involve pre-processing both the query and the string to be searched, and having more information for the pre-processing could potentially yield a faster search.
Of course, this all depends on CLR internals and your particular requirements - test, test, test.
If you want to capture more information about your text and its relation to the surrounding document, I'd suggest looking at the HtmlAgility library for parsing your document.
Here's how to do it with regex, sure regex isn't the best method, but if this is a one time thing working with an html parser is probably more than you are bargaining for
Match myMatch = Regex.Match(input,
@"<div class=""box-round"">.*?<li>(.*?)</ol>", Regex.Singleline);
if (myMatch.Success)
{
}