CString類常用方法----Left(),Mid(),Right()

CString Left( int nCount ) const;                   //從左邊1開始獲取前 nCount 個字符

CString Mid( int nFirst ) const;                      //從左邊第 nCount+1 個字符開始,獲取後面所有的字符

CString Mid( int nFirst, int nCount ) const;    //從左邊第 nFirst+1 個字符開始,獲取後面  nCount 個字符

CString Right( int nCount ) const;                  //從右邊1開始獲取從右向左前 nCount 個字符

注:

     在函數後面加 const 的意思是:

     如果一個類聲明瞭一個常量對象,這個對象只能使用後邊帶 const 這個的方法.

例:

 CString a,b;
 a = "123456789";


 b = a.Left(4);   //值爲:1234
 b = a.Mid(3);    //值爲:456789
 b = a.Mid(2, 4); //值爲:3456
 b = a.Right(4);  //值爲:6789

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章