前言:
转载请附上连接,本帖原创请勿照抄。
一、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);