Adds a line break to the text, if not empty. - CSharp System

CSharp examples for System:String Format

Description

Adds a line break to the text, if not empty.

Demo Code


using System.Text.RegularExpressions;
using System;/*from   w w  w . ja va2 s .co m*/

public class Main{
        /// <summary>
        /// Adds a line break to the text, if not empty.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static string AddCrIfNotEmpty(this string text)
        {
            return text.IsNullOrEmpty() ? "" : text + Environment.NewLine;
        }
        /// <summary>
        /// Determines whether the specified source string is null or empty.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>
        ///   <c>true</c> if the specified source string is null or empty; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNullOrEmpty(this string source)
        {
            return string.IsNullOrEmpty(source);
        }
}

Related Tutorials