Logo

Programming-Idioms

History of Idiom 110 > diff from v37 to v38

Edit summary for version 38 by arouene:
[Cpp] align curly bracket

Version 37

2019-09-26, 17:58:16

Version 38

2019-09-26, 17:59:31

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>
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;
  }
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
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/
Doc URL
http://www.cplusplus.com/reference/cctype/isspace/
Demo URL
http://cpp.sh/8ifsjg
Demo URL
http://cpp.sh/8ifsjg