IF ELSE CONDITION

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")); 
         }

Answers


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 add L"[" + 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 to L"ë", according to CString if one is normalized and the other isn't. Windows has the CompareStringEx API, which is the swiss-army-knife of string comparisions and can deal with such details.


Need Your Help

Connections will not close when using Transaction Binding=Explicit Unbind; in connection string

c# sql-server transactions timeout connection-string

I´m using Transaction Binding=Explicit Unbind in the connection string as recommended here since I´m also using TransactionScope with timeout. The problem is that the connections does not seem to c...

Jquery UI Tabs: Strategy for using included files

php jquery ajax jquery-ui jquery-ui-tabs

I have an application using Jquery's UI Tabs for an overall menu, and they're great. However, I've come to a strategy question when implementing the new format.