Trims the string or returns empty string if the value is null - CSharp System

CSharp examples for System:String Strip

Description

Trims the string or returns empty string if the value is null

Demo Code

// Copyright (c) 2012 Computer Technology Solutions, Inc.  ALL RIGHTS RESERVED
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*from   w  ww. j  a  v a  2s  .c om*/

public class Main{
        /// <summary>
        /// Trims the string or returns empty string if the value is null
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string TrimOrEmpty(this string value)
        {
            return string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim();
        }
}

Related Tutorials