Export (0) Print
Expand All

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

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.

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

Community Additions

ADD
Show:
© 2014 Microsoft