定义CSTRING 要从找到的一个串截取这个串怎么办???

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:11:40
定义CSTRING 要从找到的一个串截取这个串怎么办???

CString = "abcde base64 baaaaa"
要把base64后面的字符串保留.怎么处理????

现在你给出的字符串已经知道了长度,而且也知道分隔位置在哪儿,直接可以用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个字符的

CString str="abcde base64 baaaaa";
CString findstr="base64";
CString mystr;
int k=str.Find(findstr)+findstr.GetLength();
mystr= str.Right(str.GetLength()- k);
AfxMessageBox(mystr);

CString cs;

返回左边的值,cs.left(int x) x为几位;

返回右边的值,cs.right(int x) x为几位;

cs.GetLength();;