ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsNullOrEmptyOrWhiteSpace

It returns true if string is null or empty or just a white space otherwise it returns false.

Source

public static bool IsNullOrEmptyOrWhiteSpace(this string input)
{
   return string.IsNullOrEmpty(input) || input.Trim() == string.Empty;
}

Example

Assert.IsTrue(IsNullOrEmptyOrWhiteSpace(null));
Assert.IsTrue(IsNullOrEmptyOrWhiteSpace(string.Empty));
Assert.IsTrue(IsNullOrEmptyOrWhiteSpace("   "));
Assert.IsFalse(IsNullOrEmptyOrWhiteSpace("TestValue"));

Author: Omkar Panhalkar

Submitted on: 7 mei 2012

Language: C#

Type: System.String

Views: 7706