CString 判断存在中文,大小写字母及标点


//Unicode 字符集
CString str =  _T("068654abc一叶-+=*知秋ABC");
CString digit,punctuation,Chinese,capitalLetter,lowercase;
for(int i = 0 ; i <str.GetLength();i++)
{int unicode = (int)str.GetAt(i);if (unicode <= '9' && unicode >= '0'){digit += str.GetAt(i);}else if (unicode <= 'z' && unicode >= 'a'){lowercase += str.GetAt(i);}else if (unicode <= 'Z' && unicode >= 'A'){capitalLetter += str.GetAt(i);}else if (unicode > 255){Chinese += str.GetAt(i);}else{punctuation += str.GetAt(i);}
}//多字节字符集
CString str;   
str = "0123abc一叶-+=*知秋ABC";   
int lens;   
lens = (int)strlen(str);   
unsigned char Chinese[20],capitalLetter[20],lowercase[20],digit[20],punctuation[20];
unsigned char ansi;   
int hanzi_len,daxiezimu_len,xiaoxiezimu_len,shuzi_len,biaodianfuhao_len;
hanzi_len=daxiezimu_len=xiaoxiezimu_len=shuzi_len=biaodianfuhao_len=0;
for(int i=0;i<lens;i++)
{   ansi = str[i];   if (ansi<= '9' && ansi >= '0'){digit[shuzi_len++] = ansi;}else if (ansi <= 'z' && ansi >= 'a'){lowercase[xiaoxiezimu_len++] = ansi;}else if (ansi <= 'Z' && ansi >= 'A'){capitalLetter[daxiezimu_len++] = ansi;}else if (ansi > 127){Chinese[hanzi_len++] = ansi;Chinese[hanzi_len++] = str[++i];}else{punctuation[biaodianfuhao_len++] = ansi;}
} 



digit[shuzi_len] = '\0';   
capitalLetter[daxiezimu_len] = '\0';
lowercase[xiaoxiezimu_len] = '\0'; 
punctuation[biaodianfuhao_len] = '\0'; 
Chinese[hanzi_len] = '\0'; 


本文链接:https://my.lmcjl.com/post/12081.html

展开阅读全文

4 评论

留下您的评论.