I've got this code that checks for the empty or null string. It's working in testing.
eitherStringEmpty= (email, password) -> emailEmpty = not email? or email is '' passwordEmpty = not password? or password is '' eitherEmpty = emailEmpty || passwordEmpty test1 = eitherStringEmpty "A", "B" # expect false test2 = eitherStringEmpty "", "b" # expect true test3 = eitherStringEmpty "", "" # expect true alert "test1: #{test1} test2: #{test2} test3: #{test3}"
What I'm wondering is if there's a better way than not email? or email is ''
. Can I do the equivalent of C# string.IsNullOrEmpty(arg)
in CoffeeScript with a single call? I could always define a function for it (like I did) but I'm wondering if there's something in the language that I'm missing.
You can use the IsNullOrWhiteSpace method to test whether a string is null , its value is String. Empty, or it consists only of white-space characters.
isEmpty(<string>) Checks if the <string> value is an empty string containing no characters or whitespace. Returns true if the string is null or empty.
isEmpty(String) , which checks if a string is an empty string or null. It also provides the StringUtils. isBlank(String) method, which also checks for whitespace. That's all about determining whether a String is empty or null in Java.
Both String#isEmpty and String#length can be used to check for empty strings. To be precise, String#trim will remove all leading and trailing characters with a Unicode code less than or equal to U+0020.
Yup:
passwordNotEmpty = not not password
or shorter:
passwordNotEmpty = !!password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With