473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tricky string replacement

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
Nov 21 '05 #1
3 1230
Roshawn Dawson <ud****@bellsouth.net> wrote in news:#1$n07xdFHA.2664
@TK2MSFTNGP15.phx.gbl:
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/
Nov 21 '05 #2
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

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

Nov 21 '05 #3
"Roger" <ro***@pcsrevenuecontrol.com> schrieb:
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/UserSamples/Details.aspx?SampleGuid=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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Juha Suni | last post by:
Hi! I have managed to live without using too much regular expressions so far, and now that I need one, I need some help too. I have a string containing a (possibly large) block of html. I need...
5
by: Roose | last post by:
How can I do a "".replace operation which tells me if anything was actually replaced? Right now I am doing something like: if searchTerm in text: text = text.replace( searchTerm, 'other' ) ...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
by: Mark Sandfox | last post by:
I have a tricky control validation issue. I have probably designed this the wrong way but here is what I have. I have 6 TextBoxes; tbPN, tbA, tbC, tbS, tbZ, tbDOB and there are 20 of each with...
35
by: jacob navia | last post by:
Hi guys! I like C because is fun. So, I wrote this function for the lcc-win32 standard library: strrepl. I thought that with so many "C heads" around, maybe we could improve it in a...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
21
by: gary | last post by:
How would one make the ECMA-262 String.replace method work with a string literal? For example, if my string was "HELLO" how would I make it work in this instance. Please note my square...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
11
by: windandwaves | last post by:
Hi Folk I need to write a tricky replacement function. C = replace A with B in C C = replace D with E in C examples of A could be "a cat climbs a tree", examples of B could be
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.