Convert New Lines To Html Line Breaks Preserve Space - CSharp System

CSharp examples for System:String HTML

Description

Convert New Lines To Html Line Breaks Preserve Space

Demo Code



public class Main{
        public static string ConvertNewLinesToHtmlLineBreaksPreserveSpace(this string str)
        {//ww  w .  ja v  a  2s  .  co m
            return str.Replace("\r\n", "<br/>")
                    .Replace("\r", "<br/>")
                    .Replace("\n", "<br/>")
                    .Replace("  ", "&nbsp;");
        }
}

Related Tutorials