Logo

Programming-Idioms

History of Idiom 110 > diff from v49 to v50

Edit summary for version 50 by programming-idioms.org:
Restored version 48

Version 49

2020-07-28, 12:05:01

Version 50

2020-08-09, 18:00:25

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Variables
blank,s
Code
bool blank = s?.trim()?.isEmpty ?? true;
Code
final blank = s == null || s.trim() == '';
Comments bubble
? -> null safe check
?? -> on null
Origin
https://stackoverflow.com/a/52948927