problem with string.Contains()

  • Thread starter Thread starter Jeff
  • Start date Start date
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?
 
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?
 
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...
 
opps, my typo when creating this post.
I mean:
if (line.Contains( "</table>" ))
{
boolean = false;
}
 
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.
 
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.
 
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.
 
Back
Top