Search This Blog

Sunday, November 29, 2009

String Cstring comparision



/*
string and CSting Find, mid, left funtion
Example and comparison.
*/



#include <string> //string
using namespace std; //string


string strSample,strLeft,strRight,str;
size_t pos=0;
strSample="This is my sample";

pos=strSample.find("my");
if(pos!=string::npos)
{
strLeft=strSample.substr(0,pos);
//This is

strRight=strSample.substr(pos);
//my sample

str=strSample.substr(pos+strlen("my"));
// sample
}


CString csSample,csLeft,csRight,csStr;
int nPos=-1;
csSample="This is my sample";
if( (nPos=csSample.Find("my"))>-1)
{
csLeft=csSample.Left(nPos);
//This is

csRight=csSample.Mid(nPos);
//my sample

csStr=csSample.Mid(nPos+_tcslen("my"));
// sample

}

No comments: