Replace \r\n or \n by - CSharp System

CSharp examples for System:String Replace

Description

Replace \r\n or \n by

Demo Code


using System.Threading;
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;// w  w  w  .java 2  s.c o m

public class Main{
        /// <summary>
        /// Replace \r\n or \n by <br />
        /// from http://weblogs.asp.net/gunnarpeipman/archive/2007/11/18/c-extension-methods.aspx
        /// </summary>

        /// <param name="s"></param>
        /// <returns></returns>
        public static string Nl2Br(string s)
        {
            return s.Replace("\r\n", "<br />").Replace("\n", "<br />");
        }
}

Related Tutorials