前言:
转载请附上连接,本帖原创请勿照抄。
一、CString 截取字符串
1.Left(int nCount)
CString StrOnFind = "", StrOnFindT = "";
StrOnFind = "0a2b3c4d5e6f";
//从左侧开始截取字符串
StrOnFindT = StrOnFind.Left(2);//0a
AfxMessageBox(StrOnFindT);
StrOnFindT = StrOnFind.Left(4);//0a2b
AfxMessageBox(StrOnFindT);
2.Mid(int nFirst)和Mid( int nFirst, int nCount)
CString StrOnFind = "", StrOnFindT = "";
StrOnFind = "0a2b3c4d5e6f";
//从开始4个字符之后截取剩下的字符
StrOnFindT = StrOnFind.Mid(4); //3c4d5e6f
AfxMessageBox(StrOnFindT);
//从开始4个字符之后截取两个字符
StrOnFindT = StrOnFind.Mid(4,2);//3c
AfxMessageBox(StrOnFindT);
3.Right(int nCount)
CString StrOnFind = "", StrOnFindT = "";
StrOnFind = "0a2b3c4d5e6f";
//从末尾开始截取4个字符
StrOnFindT = StrOnFind.Right(4);//5e6f
AfxMessageBox(StrOnFindT);
本文详细介绍了使用CString类进行字符串截取的三种方法:Left、Mid和Right函数的应用。通过实例演示了如何从字符串的左端、指定位置及右端截取特定长度的子串。
2575

被折叠的 条评论
为什么被折叠?



