I am working on the visual studio c++ and using these lines in my program.
Whenever i typed Get status , output is not “Good”. the output will always be “invalid command” independent of Cstring strText . first two conditions are not working .
Kindly help . It should be worked according to the input strText.
if ( strText == _T("Get status") )
{
MessageBox(_T("Good"));
}
else if ( strText == _T("change") )
{
MessageBox(_T("Bad"));
}
else
{
MessageBox(_T("Invalid Command"));
}
CString::operator==performs an exact case-sensitive match. If there’s a mismatch in case or whitespace, then the strings will compare differently. I can’t tell what’s the problem in your case. Perhaps you could addL"[" + strText + L"]"to your messagebox, to see if there’s some whitespace you overlooked.In fact, even though CString claims to support Unicode, it doesn’t. Two Unicode strigns that are formally identical, but differ in normalization are considered distinct.
L"ë"may not be equal toL"ë", according toCStringif one is normalized and the other isn’t. Windows has theCompareStringExAPI, which is the swiss-army-knife of string comparisions and can deal with such details.