Click here to Skip to main content
15,168,695 members
Articles / General Programming / String
Alternative
Tip/Trick
Posted 12 Aug 2010

Stats

14.4K views
1 bookmarked

.NET 4: string.IsNullOrWhitespace()

Rate me:
Please Sign up or sign in to vote.
3.33/5 (2 votes)
12 Aug 2010CPOL
public static class StringExtensions { public static bool IsNullOrWhitespace(this string s) { if (null == s) return true; return string.IsNullOrEmpty(s.Trim()); } }
C#
public static class StringExtensions
    {
        public static bool IsNullOrWhitespace(this string s)
        {
            if (null == s) return true;
            return string.IsNullOrEmpty(s.Trim());
        }
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jfriedman
Software Developer (Senior)
United States United States
Livin in a lonely world, caught the midnight train going anywhere... Only thing is it was a runaway train... and it ain't ever goin back...
мала ка на хари, Trahentes ex exsilium

Comments and Discussions

 
GeneralThank you for clarifying however... Whitespace variants can... Pin
jfriedman13-Aug-10 11:30
Memberjfriedman13-Aug-10 11:30 
Thank you for clarifying however...

Whitespace variants can be matched with a RegEx and are outside the scope of the name of the functions which implies Whitespace not WhiteSpace Variants...

http://www.csharp411.com/remove-whitespace-from-c-strings/

The name of the function is not IsNullOrWhitespaceOrNewLineorTabOrSomeOtherCharacterWhichTakes0Space()
GeneralRe: I assist carrol_jhara in the broader definition of <B>White<... Pin
Andreas Gieriet26-Feb-12 11:48
professionalAndreas Gieriet26-Feb-12 11:48 
GeneralReason for my vote of 2 will fail on whitespaces variants Pin
carrol_jhara12-Aug-10 19:46
Membercarrol_jhara12-Aug-10 19:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.