views:

586

answers:

3

Hi all,

I was wondering if there is a native C++ (or STL/Boost) function which will search a CString for a specified string?

e.g.

CString strIn = "Test number 1";
CString strQuery = "num";

bool fRet = SomeFn(strIn, StrQuery);

if( fRet == true )
{
  // Ok strQuery was found in strIn
 ...

I have found a small number of functions like CompareNoCase IndexOf etc... but so far they don't really do what I want them to do (or use CLR/.Net)

Thanks!

+2  A: 

string::find

Pukku
+2  A: 

Have you tried CString::Find?

It's not STL or boost but since you have two CString's it seems the most reasonable method to use.

fhe
+6  A: 

CString::Find() is what you want, one of the overloads does sub-string searching.

CString strIn = "test number 1";
int index = strIn.Find("num");
if (index != -1)
    // ok, found
gbjbaanb