Created
September 6, 2012 08:29
-
-
Save sandrock/3653055 to your computer and use it in GitHub Desktop.
Inserts HTML line breaks (<br />) before all newlines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringTransformer | |
{ | |
/// <summary> | |
/// Inserts HTML line breaks (<br />) before all newlines. | |
/// </summary> | |
/// <param name="text">text containing lines</param> | |
/// <returns></returns> | |
public static string AddHtmlLineBreaks(this string text) | |
{ | |
if (text == null) | |
return null; | |
if (text.Contains("\r\n")) | |
return text.Replace("\r\n", "<br />\r\n"); | |
else if (text.Contains("\n")) | |
return text.Replace("\n", "<br />\n"); | |
else if (text.Contains("\r")) | |
return text.Replace("\r", "<br />\r"); | |
else | |
return text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment