I'am looking for an command to test if var1 isin var2 e.g. when var1 is "This is a test" and var2 is "test" the command should give back true or 1 or something like that.
Any ideas?
THX
Printable View
I'am looking for an command to test if var1 isin var2 e.g. when var1 is "This is a test" and var2 is "test" the command should give back true or 1 or something like that.
Any ideas?
THX
Wow, same code in two posts in a row. Let's keep this train running.Code:for (int i = 0; i < 1 + var1.length() - var2.length(); i++)
if (var1.substr(i,var2.length()) == var1)
return true;
This is what the string's find member function is for:
Code:string var1 = "This is a test";
string var2 = "test";
if( var1.find(var2) != string::npos )
cout << "Found it." << endl;
else
cout << "Couldn't find it." << endl;
Oh, what's the point of programming? Everything's already been programmed already. :p
[EDIT]
I make redundant people look not reduntant.