Export (0) Print
Expand All


Searches this string for the first match of a character or substring.

int Find(
   PCXSTR pszSub,
   int iStart=0
) const throw( );
int Find(
   XCHAR ch,
   int iStart=0
) const throw( );



A substring to search for.


The index of the character in the string to begin the search with, or 0 to start from the beginning.


A single character to search for.

The zero-based index of the first character in this CStringT object that matches the requested substring or characters; -1 if the substring or character is not found.

The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).

//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;

CAtlString s( "abcdef" );
_ASSERT( s.Find( 'c' ) == 2 );
_ASSERT( s.Find( "de" ) == 3 );

CAtlString str("The waves are still");
int n = str.Find('e', 5);
_ASSERT(n == 7);

For another example, see ISAPIFilter Sample: Maps URLs to Parameterized Queries.

Community Additions

© 2014 Microsoft