Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to find a sub string in a string.

Example:
CString _mystring("MohanBabu");


I want to check the string "Babu" whether it exists in the given string or not. Pls help me with this.
Posted
Updated 14-Sep-11 0:39am
v2

Use CStringT::Find method[^].
(There's even an example!).
 
Share this answer
 
v2
You can use CSting::Find
http://msdn.microsoft.com/en-us/library/aa314323(v=vs.60).aspx[^]

C++
if (_mystrings.Find("Babu") >= 0)
{
  //found
}
else
{
  //not found
}
 
Share this answer
 
C#
int Find( TCHAR ch ) const;

int Find( LPCTSTR lpszSub ) const;

int Find( TCHAR ch, int nStart ) const;

int Find( LPCTSTR pstr, int nStart ) const;


C#
CString str("abcdef");
if ( str.Find("def") != -1)
{
    printf("found");
}
else
{
    printf("not found");
}

C++

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900