Logo

Programming-Idioms

History of Idiom 110 > diff from v13 to v14

Edit summary for version 14 by :
New Haskell implementation by user [antalsz]

Version 13

2016-02-16, 23:21:37

Version 14

2016-02-18, 16:58:03

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.

Code
$blank = !$s || $s=~/^\s*$/;
Code
$blank = !$s || $s=~/^\s*$/;
Comments bubble
Left part catch undefined or empty.
Right part catches "whitespaces only".
Comments bubble
Left part catch undefined or empty.
Right part catches "whitespaces only".
Imports
import "strings"
Imports
import "strings"
Code
blank := strings.TrimSpace(s) == ""
Code
blank := strings.TrimSpace(s) == ""
Comments bubble
Trim s, then check if empty.
Comments bubble
Trim s, then check if empty.
Doc URL
https://golang.org/pkg/strings/#TrimSpace
Doc URL
https://golang.org/pkg/strings/#TrimSpace
Demo URL
http://play.golang.org/p/1dvSNEObOs
Demo URL
http://play.golang.org/p/1dvSNEObOs
Imports
import org.apache.commons.lang.StringUtils;
Imports
import org.apache.commons.lang.StringUtils;
Code
boolean blank = StringUtils.isBlank(s);
Code
boolean blank = StringUtils.isBlank(s);
Comments bubble
This uses external library Apache Commons Lang.
Comments bubble
This uses external library Apache Commons Lang.
Doc URL
https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#isBlank%28java.lang.String%29
Doc URL
https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#isBlank%28java.lang.String%29