Click here to Skip to main content
15,112,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Updated 24-Jan-12 2:45am


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,

SteveAdey 25-Jan-12 10:35am
You can, but be careful about performance, especially if you're calling it a lot.
var str = "Cobalt II</br>".Replace("</br>", string.Empty);
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.
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
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.

You can use the String.Replace method:
string str="Cobalt II</br>";
str= str.Replace("</br>", string.Empty);
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.
LanFanNinja 24-Jan-12 8:41am
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.


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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900