what about this?
stringtest(string &s)
{
if(string.length()<1)
return -2
std::string begin(' ?');
if(begin.find(s.front())>1)
//test if first character of s is in begin
{
unsigned found = s.find_first_not_of(' ',1)
//checks if there are any other char then ' ' after the first char
if(found >s.length())
return s.at(0);
}
else if(begin.find(s.back())>1)
//test if last character of s is in begin
{
unsigned found = s.find_last_not_of(' ',s.length()-1);
//checks if there are any other char then ' ' before the last char
if(found !=std::string::npos)
return s.at(s.length()-1);
}
if(s.length()==1 && s.front()== ' ')
return -1
else return -2
}
solved find a single char in a string [closed]