3 回答

TA貢獻1773條經(jīng)驗 獲得超3個贊
CString 有下面幾個函數(shù)
Mid Extracts the middle part of a string (like the Basic MID$ function).
Left Extracts the left part of a string (like the Basic LEFT$ function).
Right Extracts the right part of a string (like the Basic RIGHT$ function).
SpanIncluding Extracts a substring that contains only the characters in a set.
SpanExcluding Extracts a substring that contains only the characters not in a set.
點 Mid
CString::Mid
CString Mid( int nFirst ) const;
throw( CMemoryException );
CString Mid( int nFirst, int nCount ) const;
throw( CMemoryException );
Return Value
A CString object that contains a copy of the specified range of characters. Note that the returned CString object may be empty.
Parameters
nFirst
The zero-based index of the first character in this CString object that is to be included in the extracted substring.
nCount
The number of characters to extract from this CString object. If this parameter is not supplied, then the remainder of the string is extracted.
Remarks
Extracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The function returns a copy of the extracted substring. Mid is similar to the Basic MID$ function (except that indexes are zero-based).
For multibyte character sets (MBCS), nCount refers to each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters.
Example
The following example demonstrates the use of CString::Mid.
// example for CString::Mid
CString s( _T("abcdef") );
ASSERT( s.Mid( 2, 3 ) == _T("cde") );
第2到第4(序號是從0開始的 indexes are zero-based,第2個就是1,2到4總共3個字符)
s,Mid(1,3)

TA貢獻1802條經(jīng)驗 獲得超4個贊
用CString的Mid函數(shù),第一個參數(shù)是從第幾個開始,第二個參數(shù)是取多少個,返回值是一個新的CString對象。
如CString str = "123456";
CString substr = str.Mid(2,2);
返回“34“
- 3 回答
- 0 關注
- 1663 瀏覽
添加回答
舉報