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, ChTraitsCRT<TCHAR>>> CAtlString;

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

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

Header: cstringt.h

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft