While working on a ASP.NET site, I needed to change the code in the codebehind pages in C# to convert \n to <br /> tags. I was working on a product review system for an ecommerce site, and when a user types in a review and presses enter, the line break didn’t convert once the review was outputted to the page.
Here’s a quick way I did it. Make a new regex pattern and then a for loop to loop through every row that your outputting. Then use the Replace method to swap it out for <br /> tags. Here’s a summary of the relavent code.
using System.Text.RegularExpressions;
Regex rgx = new Regex("\n");
//for loop code
outputString = rgx.Replace(inputString, "<br />");
//end for loop code
Similar Posts
Share
- Deactivate Facebook Fail – Platform Application Error
- Solving Problems by Learning to be Patient
- URL Rewrite using Apache rules Under IIS7
Posted in Web Engineering
Comments 0



