This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #110 Check if string is blank
Set the boolean blank to true if the string s is empty, or null, or contains only whitespace ; false otherwise.
- Ada
- C
- Clojure
- Cobol
- C++
- C#
- C#
- D
- Dart
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Haskell
- Haskell
- JS
- Java
- Java
- Java
- Java
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Rust
- Rust
- Scala
- Scheme
- Smalltalk
- VB
bool blank = true;
for (const char *p = s; *p; p++) {
if (!isspace(*p)) {
blank = false;
break;
}
}
s has type char*
bool blank = false;
if (s.empty() || std::all_of(s.begin(), s.end(), [](char c){return std::isspace(c);})) {
blank = true;
}
s must be of type std::string
check if s is empty or if all of its characters are spaces, horizontal tabs, newlines, vertical tabs, feeds or carriage return
check if s is empty or if all of its characters are spaces, horizontal tabs, newlines, vertical tabs, feeds or carriage return
Blank = string:is_empty(string:trim(S)).
trimming the string to remove leading/trailing whitespaces and then checking if it's empty
val blank = Option(s).forall(_.trim.isEmpty)
Use strip (Java 11) instead of trim for Unicode-awareness, or more simply use isBlank (Java 11)
Option(s) ensures that null is handled.
Option(s) ensures that null is handled.