Dave's Brain

Browse - Programming Tips - What's the best way to check of a std::string is all space characters?

Date: 2008jun27
Language: C/C++

Q.  What's the best way to check of a std::string is all space characters?

A.  This function does it nicely.

static const char *szSpaceChars = " \t\r\n"; bool is_std_string_all_space(const std::string &str) { if (str.empty()) return true; return str.find_first_not_of(szSpaceChars) == std::string::npos; }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.