CString::Mid

此成員函式從此?>CString對象中提取一個長度為nCount個字元的子串,從nFirst(從零開始的索引)指定的位置開始。此函式返回一個對所提取的字元串的拷貝。Mid類似於Basic MID$函式(除了索引是從零開始的)。

基本介紹

  • 中文名:CString::Mid
  • 外文名:CString::Mid
說明,參數,

說明

CString Mid( int nFirst ) const;
throw( CMemoryException );
CString Mid( int nFirst, int nCount ) const;
throw( CMemoryException );
返回一個包含指定範圍字元的拷貝的CString對象。注意,這個返回的CString對象可能是空的。

參數

nFirst 此CString對象中的要被提取的子串的第一個字元的從零開始的索引。
nCount 要從此CString對象中提取的字元數。如果沒有提供這個參數,則字元串的其餘部分都被提取。
對於多位元組字元集(MBCS),nCount指的是每8位字元的數目;也就是說,在一個多位元組字元中開始和結尾位元組被算作兩個字元。
示例:下面的例子說明了如果如何使用CString::Mid。
// CString::Mid示例:
CString s( _T("abcdef") );
ASSERT( s.Mid( 2, 3 ) == _T("cde") );
以下為MSDN說明:
CString::Mid
This method extracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The method returns a copy of the extracted substring. Mid is similar to the Basic MID$ function, except that indexes are zero-based.
CString Mid(
int nFirst,
int nCount )
CString Mid(
int nFirst)
const;
Parameters
nFirst
Specifies the zero-based index of the first character in this CString object that is to be included in the extracted substring.
nCount
Specifies the number of characters to extract from this CString object. If this parameter is not supplied, the remainder of the string is extracted.
Return Value A CString object that contains a copy of the specified range of characters. Note that the returned CString object may be empty.
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") );

相關詞條

熱門詞條

聯絡我們