Partager via


CStringT::Find

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( );

Parameters

  • pszSub
    A substring to search for.

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

  • ch
    A single character to search for.

Return Value

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.

Remarks

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

Example

// 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);   

Requirements

Header: cstringt.h

See Also

Concepts

CStringT Class

CStringT Members