判断字符串中的每一位的ASCII值是否在0x30-0x39(0-9)、0x61-0x7A(a-z)、0x41-0x5A(A-z)、0x5F("_")之内即可

解决方案 »

  1.   

    CString s1;
    s1 = "your string";
    for(int i=0;i<strlen(s1);i++)
    {
        if(0x30<=(BYTE)s1[i]<=0x39
            ||0x61<=(BYTE)s1[i]<=0x7a
            ||0x41<=(BYTE)s1[i]<=0x5a
            ||(BYTE)s1[i]=0x5f)
        {
            .......;
        }
        else
        {
           .......;
        }
    }
      

  2.   

    BOOL ISValid
    {
    CString str;
    for(int i=0;i<str.GetLength();i++)
    {
        if('0'<=str[i]<='9'||'a'<=str[i]<='z'
            ||'A'<=str[i]<='Z'
            ||str[i]== '_')
        {
         return TRUE ;
         }
        else
         return FALSE;}}
     
     
    Top 
      

  3.   

    BOOL CheckString(CString str)
    {
     int i;
     BYTE j;
     for(i=0;i<str.GetLength();i++)
     {
         j = str.GetAt(i);
         if (j<30|| j>39)
         {
            return TRUE;
         }
      }
      return FALSE;
    }这个是区分是否在0-9内的,别的可以类推
      

  4.   

    CString::operator [ ] 
    TCHAR operator []( int nIndex ) const;
    Parameters
    nIndex
    Zero-based index of a character in the string.
    Res
    You can think of a CString object as an array of characters. The overloaded subscript ([]) operator returns a single character specified by the zero-based index in nIndex. This operator is a convenient substitute for the GetAt member function.
    Important   You can use the subscript ([]) operator to get the value of a character in a CString, but you cannot use it to change the value of a character in a CString.
    Example
    The following example demonstrates the use of CString::operator [ ].
    例子:
    CString s( "abc" );
    ASSERT( s[1] == 'b' );
      

  5.   

    BOOL IsStringAlphaNumeric(CString str)
    {
        int i;
        for (i=0; i<str.GetLength() && (IsCharAlphaNumeric(str[i]) || str[i] == '_'); i++);
        return (i == str.GetLength() && i != 0);  // zero length string returns FALSE
    }
      

  6.   

    BOOL IsStringAlphaNumeric(CString& str)  // should use reference
    {
        int i;
        for (i=0; i<str.GetLength() && (IsCharAlphaNumeric(str[i]) || str[i] == '_'); i++);
        return (i == str.GetLength() && i != 0);  // zero length string returns FALSE
    }