Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

problem with string.Contains()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 10 Mar 2008 15:53 GMT
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?
Jon Skeet [C# MVP] - 10 Mar 2008 15:57 GMT
> 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
[quoted text clipped - 10 lines]
>
> any suggestions?

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

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Jeff - 10 Mar 2008 16:35 GMT
opps, my typo when creating this post.
I mean:
if (line.Contains( "</table>" ))
{
    boolean = false;
}

>> I'm trying to search a string to determine if the string contains
>> </table>,
[quoted text clipped - 14 lines]
>
> Did you mean to look for " </table>" including a leading space?
Jon Skeet [C# MVP] - 10 Mar 2008 16:40 GMT
> opps, my typo when creating this post.
> I mean:
> if (line.Contains( "</table>" ))
> {
>      boolean = false;
> }

Well, if you've got a line which contains "</table>" that will
certainly find it.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Marc Gravell - 10 Mar 2008 16:05 GMT
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...
Jeff - 10 Mar 2008 16:57 GMT
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
>
[quoted text clipped - 14 lines]
>
> any suggestions?
Christopher Van Kirk - 11 Mar 2008 07:00 GMT
>Hey
>
[quoted text clipped - 14 lines]
>
>any suggestions?

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

Signature

Posted via a free Usenet account from http://www.teranews.com

Robert Everett - 15 Mar 2008 07:49 GMT
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.

>>Hey
>>
[quoted text clipped - 18 lines]
>
> Check that you haven't put \t instead of /t.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.