CString::GetLength对于多字节字符集(MBCS),GetLength按每一个8位字符计数

CString::GetLength对于多字节字符集(MBCS),GetLength按每一个8位字符计数,第1张

不管是unicode还是mbcs,CString的GetLength都符合下面的规则:

CString(TEXT(a_string))::GetLength == strlen(a_string)

CString 的好弄的啊,这些都可以取指针

自己随便写个循环加判断就可以了,实在看不出难度

基本函数里也有 isdigit 之类或者自己判断 if ((('0' <= theChar) && (theChar <= '9')) || ('-' == theChar))

while

count++

如果实在没有可以设置起点的findOneOf,实在要用,也可以通过指针+偏移挪到那个位置,让FindOneOf以自己的0索引开始,但是实际0索引已经不是原字串的0索引了

//#include "stdafxh"//If the vc++60, with this line

#include <iostream>

using namespace std;

#define N 100

int main(int argc,char argv[]){

int a[26],i;

char str[N+1];

cout << "Please enter a string of letters\n";

for(i=0;i<N;){

str[i]=cinget();

if(str[i]>='a' && str[i]<='z' || str[i]>='A' && str[i]<='Z')

i++;

else

break;

}

str[i]='\0';

for(i=0;i<26;a[i++]=0);

for(i=0;str[i];a[(str[i++]&0xDF)-'A']++);

cout << endl;

for(i=0;i<26;i++)

if(a[i])

cout << char('A'+i) << ": " << a[i] << endl;

return 0;

}

运行样例:

void CCConfigureDlg::OnGetAreaItem() 

{

// TODO: Add your control notification handler code here

int Pos,ItemCount=0;

CString AreaItem="AREA1,AREA2,AREA3,AREA4,AREA5,AREA6,AREA11,AREA12";

while((Pos = AreaItemFind(',')) != -1)

{

AreaItem = AreaItemRight(AreaItemGetLength()-Pos-1);

AfxMessageBox(AreaItem);

ItemCount++;

}

SetDlgItemInt(IDC_EDIT1,ItemCount+1,TRUE);

UpdateData(FALSE);

}

下边这段代码是计算一个字符串的字符个数的,注意不是字符串长度,自己改吧,很简单

int StringCountCharsA(CHAR szTarget)

{

int nCount = 0,nCorsor = 0;

byte btChar;

btChar = (byte)szTarget;

while(0x00 != btChar)

{

nCount ++;

if(::IsDBCSLeadByte(btChar))

{

nCorsor += 2;

}else

{

nCorsor += 1;

}

btChar = (byte)(szTarget+nCorsor);

}

return nCount;

}

以上就是关于CString::GetLength 对于多字字符集(MBCS),GetLength按每一个8位字符计数全部的内容,包括:CString::GetLength 对于多字节字符集(MBCS),GetLength按每一个8位字符计数、CString字符串 如何查找指定位置后有几个连续的阿拉伯数字、c++输入一个字母字符串,统计各个字母个数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10152967.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存