Any API to find if cstring contains special characters

  • Thread starter Thread starter Alamelu
  • Start date Start date
A

Alamelu

Hi,

I want to check if cstring contains alphabets, numerics and comma. No other
characters are allowed. Any methods available in cstring?

The below code doesnt work. Could you Plz suggest any other better approach

CString strTemp = _T("abcde,54");
for(int i = 0; i <= strTemp.GetLength() ; i++)
{
if(isalnum(strTemp)
||strTemp == ",")
{
}
else
{
cout << "Contains illegal char";
}
}

Regards,
Alamelu
 
I want to check if cstring contains alphabets, numerics and comma. No other
characters are allowed. Any methods available in cstring?

The below code doesnt work. Could you Plz suggest any other better approach

CString strTemp = _T("abcde,54");
for(int i = 0; i <= strTemp.GetLength() ; i++)
{
if(isalnum(strTemp)
||strTemp == ",")
{
}
else
{
cout << "Contains illegal char";
}
}


Here's your corrected code:

CString strTemp = _T("abcde,54");
for(int i = 0; i < strTemp.GetLength() ; i++)
{
if(isalnum(strTemp)
||strTemp == ',' )
{
}
else
{
cout << "Contains illegal char";
}
}

Dave
 
I want to check if cstring contains alphabets, numerics and comma. No other
characters are allowed. Any methods available in cstring?

Depends what you mean by alphabets and numerics.

isalnum is locale sensitive.
If you call a setlocale somewhere in your application then it will
be true for any character that is an alphanumeric *for that language*
That will also include accented characters.

That functionality also makes the function a bit slower even if you don't
call setlocale.
 
Back
Top