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
This is a discussion on need a instring command within the C++ Programming forums, part of the General Programming Boards category; I'am looking for an command to test if var1 isin var2 e.g. when var1 is "This is a test" and ...
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;
Sent from my iPadŽ
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;
I used to be an adventurer like you... then I took an arrow to the knee.
Oh, what's the point of programming? Everything's already been programmed already.
[EDIT]
I make redundant people look not reduntant.
Sent from my iPadŽ