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' );
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 }
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 }
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
{
.......;
}
}
{
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
{
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内的,别的可以类推
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' );
{
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
}
{
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
}