2

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!

Konrad
  • 39,751
  • 32
  • 78
  • 114

3 Answers3

12

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
  • 51,617
  • 12
  • 104
  • 148
2

string::find

Reunanen
  • 7,921
  • 2
  • 35
  • 57
2

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,099
  • 1
  • 41
  • 44