如何比较两个CString字符串是否相同。

解决方案 »

  1.   

    CString s1,s2;
    s1="aa";
    s2="bb";
    if(s1 == s2)
    .....
    else
    ....
      

  2.   

    老大下次问之前, 自己去看看msdn.// example for CString::CompareNoCase
    CString s1( "abc" );
    CString s2( "ABD" );
    ASSERT( s1.CompareNoCase( s2 ) == -1 ); // Compare with a CString.
    ASSERT( s1.Compare( _T("ABE" ) ) == -1 ); // Compare with LPTSTR string.
      

  3.   

    Compare              Compares two strings (case sensitive). 
    CompareNoCase        Compares two strings (case insensitive). 
      

  4.   

    The lstrcmp function compares two character strings. The comparison is case sensitive. int lstrcmp(
      LPCTSTR lpString1,  // pointer to first string
      LPCTSTR lpString2   // pointer to second string
    );
     
    lstrcmpi
    The lstrcmpi function compares two character strings. The comparison is not case sensitive. int lstrcmpi(
      LPCTSTR lpString1,  // pointer to first string
      LPCTSTR lpString2   // pointer to second string
    );
      

  5.   

    CString s1,s2;
    if(0==strcpy(s1,s2)) than MessageBox("","相等");
      

  6.   

    CString::operator ==
    CString::Compare
    CString::CompareNoCase
    strcmp
    strncmp
    stricmp
    strnicmp