Hi friends ,
In your web application, some times you need to display multi-line formatted text in your txtBox. For example, the string value in your database table is -"r 001,<br/>solved<br/>" , and you have to display that value in your text as follows is the requirement-
r001,
solve
thanks
So you have to replace all the <br/> tags with new line in your database value on the time of retrieving, for that the following method will fulfill the above requirement.
- public string ReplaceBRwithNewline(string txtVal)
- {
- string newText = "";
- // Create regular expressions
- System.Text.RegularExpressions.Regex regex =
- new System.Text.RegularExpressions.Regex(@"(<br />|<br/>|</ br>|</br>)");
- // Replace new line with <br/> tag
- newText = regex.Replace(txtVal, "\r\n");
- // Result
- return newText;
- }

Tj DavisPosted Jun 22, 2017, 4:11 PM
You could cut the regex down to @"<\/? ?br ?\/?>" this will check for <br> </br> <br /> <br/>
Jaipal ReddyPosted Jun 11, 2015, 6:45 AM
txtVal.Text.Replace("<br>", "\n" )); can also works smartly.