Search This Blog

Saturday, February 7, 2009

Useful Cstring Functions



//For replacing nonprintable and non-ASCII unicode to space
CString RemoveNonPrintableCharWithSpacer(LPCSTR lpText)
{
CString csData;
for(;*lpText!='\0'; lpText++)
{
if(*lpText<0 || *lpText>255)
{
csData += " ";
}
else
{
csData += *lpText;
}
}

return csData;
}



//For counting no of small characters
unsigned int CountSmallCharacters(LPCTSTR lpText)
{
unsigned int nSCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if(*lpText>='a' && *lpText <='z')
nSCharCount++;
}
return nSCharCount;
}



//For counting no of characters
unsigned int CountCharacters(LPCTSTR lpText)
{
unsigned int nCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if( (*lpText>='a' && *lpText <='z') || (*lpText>='A' && *lpText <='Z') )
nCharCount++;
}
return nCharCount;
}

No comments: