CString截取字符串方法和示例

前言:

转载请附上连接,本帖原创请勿照抄。

一、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);

   

猜你喜欢

转载自blog.csdn.net/qq_37529913/article/details/102685226
今日推荐