Find substring

Web Site  Methods

 
Str::Find
 
CPOS Find (const STRCHAR* substr, CPOS startat = 0) const

 
Str::FindNoCase
 
CPOS FindNoCase (const STRCHAR* substr, CPOS startat = 0) const

Find will search the string, starting at the given 0-based position (by default, the beginning of the string) and return the index of the first occurrence of the given substring.  It performs a case-sensitive search. If the string cannot be found, the method returns -1.

If the startat parameter is beyond the end of the string, Str will throw an exception.

FindNoCase is exactly the same, but will do a case-insensitive search. It is somewhat slower, especially on big strings, so if you need to call it repeatedly in a performance-critical function, it is best to first produce a lowercase copy of the string object and of substr, and use Find() instead.

 

See also: Find, Replace, Compare