【文件属性】:
文件名称:VC 统计字符串中英文字符个数.rar
文件大小:12KB
文件格式:RAR
更新时间:2022-07-30 11:18:09
VC 源码-文本字符
VC 6.0 统计字符串中英文字符个数,统计时将判断中英文字符个数,分别统计有多少个字符:
UpdateData(TRUE);
//获得字符串按字节数计算的长度
int Lenth = m_strTxt.GetLength();
int nELenth = 0;//英文字符数
int nCLenth = 0;//中文字符数
int nTotalLenth = 0;//总共字符数
for(int i=0;i {
char c = m_strTxt.GetAt(i);
//是中文字符
if(c<0||c>255)
continue;
//是英文字符
else
nELenth ;
}
//计算中文字符数,每个中文字符占两个字节
nCLenth = (Lenth-nELenth)/2;
nTotalLenth = nCLenth nELenth;
m_strTotal.Format("总共字符数:%d",nTotalLenth);
m_strEnglish.Format("英文字符数:%d",nELenth);
m_strChinese.Format("中文字符数:%d",nCLenth);
UpdateData(FALSE);
【文件预览】:
codesc.net
----CharStatistic()
--------resource.h(875B)
--------CharStatistic.rc(5KB)
--------ReadMe.txt(4KB)
--------res()
--------CharStatisticDlg.cpp(5KB)
--------CharStatistic.dsp(4KB)
--------StdAfx.cpp(215B)
--------CharStatistic.dsw(551B)
--------CharStatistic.h(1KB)
--------CharStatistic.cpp(2KB)
--------StdAfx.h(1KB)
--------CharStatisticDlg.h(1KB)