ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Nl2Br

Convert a NewLine to a Html break

Source

using System;
using System.Security.Cryptography;
using System.Text;

namespace MyExamples
{
    static class StringExtensions
    {
        public static string Nl2Br(this string s)
        {
            return s.Replace("\r\n", "<br />").Replace("\n", "<br />");
        }
    }
}

Example

string s = "line1\r\n\line2";
string r = s.Nl2Br(); \\ "line1<br />line2"

Author: unknown

Submitted on: 20 nov. 2007

Language: C#

Type: System.String

Views: 7460