I have a condition checking for empty strings and it is not evaluating an empty string as expected.
I read string one char at a time:
isNumber(s: string) {
console.log('char', s);
if (s !== '' && !isNaN(Number(s))) {
console.log('is a number');
console.log('-------------');
return true;
}
console.log('NOT a number');
console.log('-------------');
}
The string is read from a csv file:
a,b,
c,d,e
The 3rd column 1st row is empty but if evaluates to true even though I have s !== '', I have confirmed the char is empty with console. Why is the empty string condition not working?
Update: Could this cause a non empty string? I initialise the variable with quotes then append to it.
cellExtraction = '';
cellExtraction += s; // <- where s should be an empty string read from file
console.log()show?" "?sis really the empty string. Therefore one can only conclude that it is not. Note thatNumber(s)whensis a string containing zero or more space characters returns0, which is a number.\r- carriage return. Line break is\nwhich has a char code of 10. You can uses.trim()to remove it and other white space characters.