Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have to remove "&lt;br&gt;" tag from my string that is stored in the database when the form is submitted. This is an example string: "Cobalt II</br>". I want to store it like this: "Cobalt II". The coding shall use C#.

Thanks for your help!
Posted
Updated 24-Jan-12 1:45am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,

I found this link python parser for converting html into plain text.

you can call python class from C# code using dynamic.

hope this will help you,

thanks
-Amit.
   
Comments
SteveAdey 25-Jan-12 10:35am
   
You can, but be careful about performance, especially if you're calling it a lot.
Rate this:
Please Sign up or sign in to vote.

Solution 3

var str = "Cobalt II</br>".Replace("</br>", string.Empty);
   
v2
Comments
Jαved 24-Jan-12 8:44am
   
Added pre tag.
LanFanNinja 24-Jan-12 8:56am
   
+5 A bit hard coded but demonstrates the use of the Replace method all the same.
SteveAdey 24-Jan-12 9:04am
   
Thanks Ninja, was trying to keep it succinct.
Rate this:
Please Sign up or sign in to vote.

Solution 4

   
Comments
Espen Harlinn 24-Jan-12 16:16pm
   
Chris Maunders comments on that page provides an excellent solution :)
Bryian Tan 24-Jan-12 23:13pm
   
look promising :)
Amir Mahfoozi 25-Jan-12 5:14am
   
+5
Rate this:
Please Sign up or sign in to vote.

Solution 5

For a more dynamic solution to your problem. I'd suggest:

Regex.Replace(source, "<.*?>", string.Empty);


This allows you to remove all types of tags not just specifically to the br tag.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hello,

You can use the String.Replace method:
string str="Cobalt II</br>";
str= str.Replace("</br>", string.Empty);
   
v5
Comments
Manfred Rudolf Bihy 24-Jan-12 7:40am
   
You are aware that strings are immutable objects? There seems to be some important part missing in your code, which by the way must be wrapped in pre tags for better readablitiy.
—MRB
LanFanNinja 24-Jan-12 8:41am
   
Correct.
sharad_sharma82 24-Jan-12 7:47am
   
i have used this but its not working for me :(
LanFanNinja 24-Jan-12 8:41am
   
The result of str.Replace("</br>", ""); needs to be assigned to str or another string.

i.e

string str = "Cobalt II</br>";
str = str.Replace("</br>", "");
sharad_sharma82 27-Jan-12 1:59am
   
Thanks LanFanNinja its working
fjdiewornncalwe 24-Jan-12 10:27am
   
There are a few things wrong with this. Along with what has been mentioned by Manfred and LanFanNinja, it is a best practice to use string.Empty instead of "".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100