名稱
CString::Find 在一個較大的字符串中查找字符或子字符串int Find( TCHAR ch ) const;int Find( LPCTSTR lpszSub ) const;int Find( TCHAR ch, int nStart ) const;int Find( LPCTSTR pstr, int nStart ) const;
返回值返回此CString對象中與需要的子字符串或字符匹配的第一個字符的從零開始的索引;如果沒有找到子字符串或字符則返回-1。 參數ch 要搜索的單個字符。lpszSub 要搜索的子字符串。nStart 字符串中開始搜索的字符的索引,如果是0,則是從頭開始搜索。如果nStart不是0,則位于nStart之前的字符不包括在搜索之內。pstr 指向要搜索的字符串的指針
說明此成員函數用來在此字符串中搜索子字符串的第一個匹配的字符。函數的重載可以接收單個字符(類似于運行時函數strchr)和字符串(類似于strstr)。
示例//下面演示第一個例子// CString::Find( TCHAR ch )CString s( "abcdef" );int n = s.Find( 'c' ); // 結果 n = 2int f = s.Find( "de" ) ; // 結果 f = 3ASSERT( n == 2 );ASSERT( f == 3 );// 下面演示第二個例子// CString::Find(TCHAR ch,int nStart)CString str("The stars are aligned");int n = str.Find('e',5); //結果 n = 12新聞熱點
疑難解答