CString::Find
This method searches this string for the first match of a substring. The method is overloaded to accept both single characters (similar to the strchr run-time function) and strings (similar to strstr).
int Find(
TCHAR
ch
)
const;
int Find(
TCHAR ch,
int nStart )
const;
int Find(
LPCTSTR lpszSub )
const;
int Find(
LPCTSTR lpszSub,
int nStart );
Parameters
- ch
Specifies a single character to search for. - lpszSub
Specifies a substring to search for. - nStart
Specifies the index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0.
Return Value
The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.
Example
// First example demonstrating
// CString::Find (TCHAR ch)
CString s("abcdef");
ASSERT(s.Find('c') == 2);
ASSERT(s.Find(_T("de")) == 3);
// Second example demonstrating
// CString::Find(TCHAR ch, int nStart)
CString str("The stars are aligned");
int n = str.Find('e', 5);
ASSERT(n == 12);
Requirements
Windows CE versions: 1.0 and later
Header file: Declared in Afx.h
Platform: H/PC Pro, Palm-size PC, Pocket PC