problem with string.Contains()

J

Jeff

Hey

..NET 3.5

I'm trying to search a string to determine if the string contains </table>,
but string.Contains don't find it. I've used WebRequest/WebReponse to
retrieve the html from a webpage and now I'm searching through this html...
this webpage contains 4 html tables. so there are 4 </table>, but my code
don't find any...

Here is part of my code, this if-statment don't get true...
string line;
if (line.Contains(" </table>" ))
{
boolean = false;
}

any suggestions?
 
J

Jon Skeet [C# MVP]

I'm trying to search a string to determine if the string contains </table>,
but string.Contains don't find it. I've used WebRequest/WebReponse to
retrieve the html from a webpage and now I'm searching through this html...
this webpage contains 4 html tables. so there are 4 </table>, but my code
don't find any...

Here is part of my code, this if-statment don't get true...
string line;
if (line.Contains(" </table>" ))
{
boolean = false;
}

any suggestions?

Did you mean to look for " </table>" including a leading space?
 
M

Marc Gravell

Might also want to check the source to see if it uses some other
casing: TABLE, Table, tAbLe, etc... depending on your conformance,
anything is possible...
 
J

Jeff

opps, my typo when creating this post.
I mean:
if (line.Contains( "</table>" ))
{
boolean = false;
}
 
J

Jeff

I've just found out why this didn't work. My mistake... the reason if
(line.Contains("</table>" )) didn't work, was because there is another
if-statement above this and that if statement wasn't true... so I've solved
it.
 
C

Christopher Van Kirk

Hey

.NET 3.5

I'm trying to search a string to determine if the string contains </table>,
but string.Contains don't find it. I've used WebRequest/WebReponse to
retrieve the html from a webpage and now I'm searching through this html...
this webpage contains 4 html tables. so there are 4 </table>, but my code
don't find any...

Here is part of my code, this if-statment don't get true...
string line;
if (line.Contains(" </table>" ))
{
boolean = false;
}

any suggestions?

Check that you haven't put \t instead of /t.
 
R

Robert Everett

Contains is case sensitive. You will have to try something like:

string myString = "<Table><TR><TD></TD></TR></Table>";

if (myString.ToUpper().Contains("</TABLE>"))
{
Console.WriteLine("Found it.");
}

or you could use regular expressions.
 

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

Top