2 回答
TA贡献1876条经验 获得超6个赞
现在你给出的字符串已经知道了长度,而且也知道分隔位置在哪儿,直接可以用CString::Right()函数获取后半截,如下:
CString str="abcde base64 baaaaa";
str=str.Right(6);//等式右边得到str的后6个字符组成的字符串然后赋值给str
如果先前不知道分割点的确切位置的话,可以用如下函数查找:
CString::Find() //1
CString::FindOneOf() //2
函数1有如下几个原型:
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR lpszSub, int nStart ) const;
函数2的原型为:
int FindOneOf( LPCTSTR lpszCharSet ) const;
找到分隔点位置后就可以截取了。
与CString::Right(int n)相对的还有CString::Left(int n),它是用来截取字符串前面n个字符的
TA贡献1895条经验 获得超3个赞
CString str="65.3 42.3 65 66 78.1 69";
CString temp;
int lenth=str.GetLength();
int nfrist=str.Find(" ");
while(1)
{
if(nfrist!=-1)
{
temp=str.Left(nfrist);
MessageBox(temp);
temp=str.Right(lenth-nfrist-1); //减掉1 为了去掉空格
str=temp;
nfrist=str.Find(" ");
lenth=str.GetLength();
}
else
{
MessageBox(str);
break;
}
}
没怎么优化 按照字符串" " 查找的 建议改成特殊字符别用空串 或者空字符' ' 没怎么优化 你自己把MessageBox 弹出来的保存就行了
- 2 回答
- 0 关注
- 121 浏览
添加回答
举报
