其中日文、中文简体、繁体没法分开,编码都是在一起的。
// UNICODE字符集
CString str = L"0123abc雲中鶴+-*ほニホ"; CString shuzi,biaodianfuhao,hanzi,daxiezimu,xiaoxiezimu; for (int i = 0 ; i <str.GetLength();i++) { int unicode = (int)str.GetAt(i); if (unicode <= '9' && unicode >= '0') { shuzi += str.GetAt(i); } else if (unicode <= 'z' && unicode >= 'a') { xiaoxiezimu += str.GetAt(i); } else if (unicode <= 'Z' && unicode >= 'A') { daxiezimu += str.GetAt(i); } else if (unicode > 255) { hanzi += str.GetAt(i); } else { biaodianfuhao += str.GetAt(i); } }
//多字节字符集 CString str; str = "0123abc雲中鶴+-*ほニホ"; int lens; lens = (int)strlen(str); unsigned char hanzi[20],daxiezimu[20],xiaoxiezimu[20],shuzi[20],biaodianfuhao[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') { shuzi[shuzi_len++] = ansi; } else if (ansi <= 'z' && ansi >= 'a') { xiaoxiezimu[xiaoxiezimu_len++] = ansi; } else if (ansi <= 'Z' && ansi >= 'A') { daxiezimu[daxiezimu_len++] = ansi; } else if (ansi > 127) { hanzi[hanzi_len++] = ansi; hanzi[hanzi_len++] = str[++i]; } else { biaodianfuhao[biaodianfuhao_len++] = ansi; } } shuzi[shuzi_len] = '\0'; daxiezimu[daxiezimu_len] = '\0'; xiaoxiezimu[xiaoxiezimu_len] = '\0'; biaodianfuhao[biaodianfuhao_len] = '\0'; hanzi[hanzi_len] = '\0';