Basically I have string of whitespace " "
or blocks of whitespace or ""
empty in some of the lines of the files and I would like to know if there is a function in C++ that checks this.
*note:* As a side question, in C++ if I want to break a string down and check it for a pattern which library should I use? If I want to code it myself which basic functions should I know to manipulate string? Are there any good references?
bool isWhitespace(std::string s){
for(int index = 0; index < s.length(); index++){
if(!std::isspace(s[index]))
return false;
}
return true;
}
std::string str = ...;
if (str.empty() || str == " ") {
// It's empty or a single space.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With