Replace part of a string as long as it matches a string array

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I need to replace parts of a string ...the string has a bunch of different things to be replaces..I was thinking about using a string[] aray...not sure how to do it tho....

here is the string that I need to relace

<![CDATA[
1967 Alfa Romeo Duetto <br /> Stock # 03313, Mileage: 0, VIN # <br /> Price: $16,750<br /> Exterior Color: Red, Interior Color: <br /> <div style="text-align: center;"><em><strong><span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: rgb(255, 0, 0);"><span style="f
]]>


<![CDATA[
ont-size: xx-large;">1967 Alfa Romeo Duetto 1600</span></span></span></strong></em></div><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-size: large;"><span style="font-family: Arial, Helvetica, sans-serif;">1967 Alfa Romeo Duetto, red with black interior, covered headlights, 64,969 on the odometer, extremely original car, mechanically sound. For $16,750</span><br style="font-family: Arial, Helvetica, sans-serif;" /><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-family: Arial, Helvetica, sans-serif;">If you have any additional questions <span style="color: rgb(0, 255, 0);"><strong>Please call 310-975-0272</strong></span> or email with any questions! We also welcome all international buyers. We can help with shipping quotes and arrangements.</span></span>
]]>

I need to replace everything in the angle bracket tags with an empty string " ".

thank you for any help

-InkedGFX

 
So, you're saying that you want to remove all the HTML tags, correct? In that case, you wouldn't use a string array. You would use Regex.Replace rather then String.Replace to replace everything that matches a pattern rather then everything that matches specific substrings. You'll need to use an appropriate pattern to prevent the entire CDATA sections being replaced. I'm not especially proficient with regular expressions as I've rarely used them but I'll see if I can come up with something. You can always look into it yourself too.

Also, is there something funky going on with that text because it looks like you break it into two CDATA sections right in the middle of specifying a font style?
 
Hang on... I suspect that those CDATA sections aren't even part of your text and you just used them to post. Is that correct? Does your text actually look like this:
C#:
1967 Alfa Romeo Duetto <br /> Stock # 03313, Mileage: 0, VIN # <br /> Price: $16,750<br /> Exterior Color: Red, Interior Color: <br /> <div style="text-align: center;"><em><strong><span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: rgb(255, 0, 0);"><span style="font-size: xx-large;">1967 Alfa Romeo Duetto 1600</span></span></span></strong></em></div><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-size: large;"><span style="font-family: Arial, Helvetica, sans-serif;">1967 Alfa Romeo Duetto, red with black interior, covered headlights, 64,969 on the odometer, extremely original car, mechanically sound. For $16,750</span><br style="font-family: Arial, Helvetica, sans-serif;" /><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-family: Arial, Helvetica, sans-serif;">If you have any additional questions <span style="color: rgb(0, 255, 0);"><strong>Please call 310-975-0272</strong></span> or email with any questions! We also welcome all international buyers. We can help with shipping quotes and arrangements.</span></span>
 
yes..that is directly from the rss feed I am attempting to parse.....I thought that looked a little funky also...I thought about using regex to do this, but I have never really tried regex before....I will look into regex now...thank you for mentioning it.....

-InkedGFX
 
thank you for helping me ...the regex suggestion was the answer...the below code works perfectly

string description_isFinal = Regex.Replace(description_final, @"\s+", "");


Thank You
-InkedGFX
 
Back
Top Bottom