Check for An Empty String


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /==============================
  2. Check for empty string
  3. string s = "hello";
  4.  
  5. // Test if a string is neither null nor empty. This has to be a static
  6. // memeber of the String class because the object may be null!
  7. if ( !String.IsNullOrEmpty( s ) ) ...
  8.  
  9. // Test if a string is empty.
  10. if ( s.Length != 0 ) ...
  11.  
  12. // Test if a string is empty. (another way, more explicit way to do it)
  13. if ( s != String.Empty ) ...

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.