• VC 判断CString字符串中各位是数字,大小写字母,符号,汉字。(UNICODE和ANSI)


    其中日文、中文简体、繁体没法分开,编码都是在一起的。
    
    
    // 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'; 
    
  • 相关阅读:
    tyvj[1087]sumsets
    tyvj[1089]smrtfun
    [bzoj3289]Mato的文件管理
    luogu[2093]零件分组
    luogu[1135]奇怪的电梯
    codevs[1300]文件排版
    luogu[1140]相似基因
    动态规划练习题 胖男孩
    动态规划练习题 汇率
    vijos[1355]车队过桥问题
  • 原文地址:https://www.cnblogs.com/aoyihuashao/p/1630701.html
Copyright © 2020-2023  润新知