0
i need a code in c++ to find a string pattern in another string.can anyone help me?
7 Respuestas
+ 1
I wrote a little program that returns true if a string is contained in another string, otherwise returns false.
https://code.sololearn.com/cgq4kWNa9g7L/#cpp
+ 1
The String class has a find method that searches for the string passed as a parameter, if the string is found returns the position of the first letter of the first match.
If the substring is not found the method returns string::npos.
if(str.find(substring) != string::npos) { return true; }
The line above means that if the string is found do some code.
More info about the find method here: http://www.cplusplus.com/reference/string/string/find/
0
Do you mean find a string that is contained in another string?
0
yes
0
tank you vey much. can u explain me line 10.
and is there any find function in strings?
0
thanx a lot
0
You're welcome!