CString的几个字符串处理函数的index问题
2007-05-02 14:14
796 查看
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.
[/code]
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") );[/code]
---------------------------------------
CString Left( int nCount ) const; throw( CMemoryException ); Return ValueA CString object containing a copy of the specified range of characters. Note that the returned CString object may be empty. ParametersnCountThe number of characters to extract from this CString object.RemarksExtracts the first (that is, leftmost) nCount characters from this CString object and returns a copy of the extracted substring. If nCount exceeds the string length, then the entire string is extracted. Left is similar to the Basic LEFT$ 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. ExampleThe following example demonstrates the use of CString::Left. [code]// example for CString::Left CString s( _T("abcdef") ); ASSERT( s.Left(2) == _T("ab") );
------------------------------------------------
int Find( TCHAR ch ) const; int Find( LPCTSTR lpszSub ) const; int Find( TCHAR ch, int nStart ) const; int Find( LPCTSTR pstr, int nStart ) const; Return ValueThe zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found. ParameterschA single character to search for.lpszSubA substring to search for.nStartThe index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0.pstrA pointer to a string to search for.RemarksSearches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr). Example// First example demonstrating // CString::Find ( TCHAR ch ) CString s( "abcdef" ); ASSERT( s.Find( 'c' ) == 2 ); ASSERT( s.Find( "de" ) == 3 ); // Second example demonstrating // CString::Find( TCHAR ch, int nStart ) CString str("The stars are aligned"); int n = str.Find('e', 5); ASSERT(n == 12);
[/code]
相关文章推荐
- 几个常用的javaScript字符串处理函数--split() .ion() .substring()和index()
- 几个常用的JavaScript字符串处理函数 split()、John()、substring()和indexOf()
- 几个常用的JavaScript字符串处理函数 split()、join()、substring()和indexOf()
- 几个非常有用的字符串处理函数!
- 几个字符串处理函数
- 常忘了的字符串处理函数的细节问题
- 2011-11-24 20:04 js 几个常用字符串处理函数
- 几个常用的Javascript字符串处理函数简介
- 字符串处理函数的一些问题
- MFC几个关于字符串处理的全局函数
- 几个常用的JavaScript字符串处理函数 – split()、join()、substring()和indexOf()
- 几个非常有用的字符串处理函数!
- C语言中的几个字符串处理函数: strcat, strncat, strcpy, strncpy, strlen
- 几个常用的JavaScript字符串处理函数 – split()、join()、substring()和indexOf()
- 再加几个MQL4 中的字符串处理函数
- php字符串处理函数常见问题
- 几个常用的JavaScript字符串处理函数 - split()、join()、substring()和indexOf()
- [delphi技术]常用的几个字符串处理函数
- C语言字符串处理的几个常用函数
- 几个常见的字符串处理函数