如判断一个字符串是不是“admin",但字符号串里面的大小写不区分,即里面也可以是”ADMIN“,也可以是“Admin",应该怎么做?

解决方案 »

  1.   

    strcmpi(...)or CString::CompareNoCase(...)
      

  2.   

    // example for CString::CompareNoCase
    CString s1( "abc" );
    CString s2( "ABD" );
    ASSERT( s1.CompareNoCase( s2 ) == -1 ); // Compare with a CString.
    ASSERT( s1.Compare( "ABE" ) == -1 ); // Compare with LPTSTR string.
      

  3.   

    char cA[]="admin";
    for(int i=0;i<sizeof(cA)-1;i++)
    {
      if(cA[i]<='a')cA[i]=cA[i]-'A'+'a';
    }
    以上是去掉cA[]中的大写字母。
      

  4.   

    Compare characters of two strings without regard to case.int _strnicmp( const char *string1, const char *string2, size_t count );
      

  5.   

    CString str1( "aDmIN" );
    CString str2;
    if( str1.MakeUpper() == "ADMIN" )
        str2 = "a";
    else
        str2 = "b";