Copy a substring from main string using CString library functions.
CString FilterCriteria ="MESSAGE=2 AND READ = 2 AND Instance=\'SMS/MMS\'
AND Folder=\'inbox\'";
CString o_filter;
Now, i want to copy Instance=\'SMS/MMS\' AND Folder=\'inbox\'
from FilterCriteria
to o_filteredFilterCriteria
.
Expected result:
o_filter = Instance=\'SMS/MMS\' AND Folder=\'inbox\'.
Program:
int Pos = FilterCriteria.find(instance);
int First_Pos = FilterCriteria.find("'");
string temp_str = FilterCriteria.substr(First_Pos+1);
string temp_str =FilterCriteria.
int Second_Pos = temp_str.find("'");
string tempInstance = FilterCriteria.substr(Pos, First_Pos+Second_Pos-
Pos+2);
temp_str = "";
Pos = FilterCriteria.find(folder);// folder position
string Fold_Str = FilterCriteria.substr(Pos);//string after the folder
First_Pos = Fold_Str.find("'");// first occurence of string
temp_str = Fold_Str.substr(First_Pos+1);// string after '
Second_Pos = temp_str.find("'");// first occurence of ' in string after '
string tempFolder=originalFilterCriteria.substr(Pos, First_Pos+Second_Pos-
Pos+2);
if ( !tempInstance.isEmpty())
{
o_filter = " AND ";
o_filter += tempInstance;
}
if (!tempFolder.isEmpty())
{
o_filter = " AND ";
o_filter += tempFolder;
}
This code works for string.h library. The same code doesn't work for CString
functions as CString library doesn't have substr() function.
CString::Mid
– UpkeepCString
class I'm not familiar with. The one I'm familiar with doesn't have a member namedgetMid
, norfind
norgetRight
. I no longer have any idea what you are talking about. – Upkeep