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

CSharp examples for System:String Strip

Description

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

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  ww w .ja va 2 s. c  o m*/

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

Related Tutorials