if ( yousaid.GetAt(current_pos) == "[A-Z]" )
-
Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)
-
Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)
The function isalpha will tell you if a character is a letter, the other way is to get a char out, like this:
CString s("dsASdFDftSaSdAaasDdR");
char a = s[0]; // Use the index to get out the char, you can use s.GetLength() to iterate over them
if (a >= 'A' && a <= 'Z') // char automatically cats to int, which is why this works nicely.
{
AfxMessageBox("Uppercase");
}If you wanted to test a whole string you could do this:
CString s("dsASdFDftSaSdAaasDdR");
CString d(s);
d.MakeUpper();if (s==d)
AfxMessageBox("All Upper");I'm sure someone else will suggest more intelligent ways of doing it, but those are the ways that spring to mind if you're using CString. If you were using basic_string you could do cool iterator stuff, but that is another story ( and CString is more useful than basic_string overall ). Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
-
Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)