Tricky string replacement

  • Thread starter Thread starter Roshawn Dawson
  • Start date Start date
R

Roshawn Dawson

Hi,

I have a string that contains text as well as some html tags. The tags
in question are <br /> tags. This is what I'm aiming for:

1. Search the string for any occurrence(s) of <br /> tags
2. If there are any, count the total number of <br /> tags found
3. For each odd-numbered <br /> tag, change it to a <p> tag
4. For each even-numbered <br /> tag, change it to a </p> tag

Any ideas on how I can do this via VB.NET?

Thanks,
Roshawn
 
Roshawn Dawson said:
1. Search the string for any occurrence(s) of <br /> tags
2. If there are any, count the total number of <br /> tags found
3. For each odd-numbered <br /> tag, change it to a <p> tag
4. For each even-numbered <br /> tag, change it to a </p> tag

Any ideas on how I can do this via VB.NET?

I havent given this too much thoguht, but you might use split and split it according ot <br /> which will
put the string into pieces in an array.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
Hi,
This looks like a job for a parser.
I wonder if an XML parser would do it.
If not, is there an HTML parser for .NET?
Anyone?
Thanks,
Roger
 
Roger said:
If not, is there an HTML parser for .NET?

Parsing an HTML file:

MSHTML Reference
<URL:http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/reference.asp>

- or -

..NET Html Agility Pack: How to use malformed HTML just like it was
well-formed XML...
<URL:http://blogs.msdn.com/smourier/archive/2003/06/04/8265.aspx>

Download:

<URL:http://www.codefluent.com/smourier/download/htmlagilitypack.zip>

- or -

SgmlReader 1.4
<URL:http://www.gotdotnet.com/Community/...mpleGuid=B90FDDCE-E60D-43F8-A5C4-C3BD760564BC>

If the file read is in XHTML format, you can use the classes contained in
the 'System.Xml' namespace for reading information from the file.
 

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

Back
Top