Check if string has letter in uppercase or lowercase

user7024664 picture user7024664 · Nov 8, 2016 · Viewed 12.4k times · Source

i would like to know if it's possible check if one letter of a string is capitalized. Other way to see it, if all letters in the string are uppercase or lowercase. Example:

string a = "aaaaAaa"; 
string b = "AAAAAa"; 

if(??){ //Cheking if all the string is lowercase
   cout << "The string a contain a uppercase letter" << endl;
}
if(??){ //Checking if all the string is uppercase
       cout << "The string b contain a lowercase letter" << endl;
}

Answer

Slava picture Slava · Nov 8, 2016

you can use standard algorithm std::all_of

if( std::all_of( str.begin(), str.end(), islower ) { // all lowercase
}