Dave's Brain

Browse - programming tips - is a std string all space

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 the trick:

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;
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, 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.