jay_t55
jay_t55

Reputation: 11652

Splitting a string in C#

I was wondering if somebody could help me use string split to get all occurrences of text in between <p> </p> tags in an HTML document?

Upvotes: 0

Views: 698

Answers (5)

Omu
Omu

Reputation: 71206

i've been doing this manually, just traversing the string in a loop and counting the <p> tags and if you found one <p and than another <p and another and than you suddenly have a </p> than you must wait until you find the 3rd </p> and there you have it

Upvotes: 0

Kev
Kev

Reputation: 119806

For the benefit of the folks who suggest RegEx, can I just point to this answer:

RegEx match open tags except XHTML self-contained tags (Stack Overflow)

Just say no.

Upvotes: 1

rerun
rerun

Reputation: 25505

Take a look at regular expressions. String split is not a good solution.

Upvotes: 2

RichardOD
RichardOD

Reputation: 29157

Sounds like you want to look at the HTML Agility Pack. It works very well on dodgy HTML documents!

Upvotes: 6

harriyott
harriyott

Reputation: 10645

That's rather a large problem for String.Split(). I'd recommend using an XML parser instead.

Upvotes: 2

Related Questions