If we need to check whether there's any value, we can do
If we want to check specifically for an empty string over null, We would think checking against
"" is our best bet, using the
To check whether a string is empty, null or undefined we can use:
To check whether a string is blank, null or undefined we can use:
To check whether a string is blank or contains only white-space:
We can use !!(not not) operator.
or use type casting:
- Both do the same function, type cast the variable to boolean, where str is a variable.
- Returns false for null,undefined,0,000,"",false.
- Returns true for string "0" and whitespace " ".
If we want to ensure that the string is not just a group of empty spaces (In our imagining this is for form validation) we need to do a replace on the spaces.
In this solution to check for an str.Empty,