Posted By

jdmays on 01/03/09


Tagged

empty String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
khouser


Check for An Empty String


 / Published in: C#
 

  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  

You need to login to post a comment.