Checking for empty String using C# with Example



Checking for empty String using C# with Example

String.IsNullOrEmpty() and String.IsNullOrWhiteSpace() 
string nullString = null; 
string emptyString = ""; 
string whitespaceString = " "; 
string tabString = "\t"; 
string newlineString = "\n"; 
string nonEmptyString = "abc123"; 
 

bool result; 
result = String.IsNullOrEmpty(nullString); // true 
// true 
result = String.IsNullOrEmpty(emptyString); 
// false 
result = String.IsNullOrEmpty(whitespaceString); 
// false 
result = String.IsNullOrEmpty(tabString); 
// false 
result = String.IsNullOrEmpty(newlineString); 
result = String.IsNullOrEmpty(nonEmptyString); // false 
result = String.IsNullOrWhiteSpace(nullString); // true 
// true 
result = String.IsNullOrWhiteSpace(emptyString); 
result = String.IsNullOrWhiteSpace(tabString); // true 
// true 
result = String.IsNullOrWhiteSpace(newlineString); 
result = String.IsNullOrWhiteSpace(whitespaceString); // true 
result = String.IsNullOrWhiteSpace(nonEmptyString); //    false 

0 Comment's

Comment Form

Submit Comment