Logo

Programming-Idioms

History of Idiom 110 > diff from v31 to v32

Edit summary for version 32 by arouene:
New Cpp implementation by user [arouene]

Version 31

2019-09-26, 16:31:48

Version 32

2019-09-26, 17:50:55

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.

Imports
#include <algorithm>
#include <cctype>
#include <string>
Code
bool blank = false;
if (s.empty() || std::all_of(s.begin(), s.end(), [](char c){return std::isspace(c);})) {
      blank = true;
  }
Comments bubble
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
Doc URL
http://www.cplusplus.com/reference/cctype/isspace/
Demo URL
http://cpp.sh/8ifsjg