0

i need a code in c++ to find a string pattern in another string.can anyone help me?

18th Oct 2018, 11:56 AM
NimaNA11
NimaNA11 - avatar
7 Respostas
+ 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
19th Oct 2018, 3:54 PM
Isaac Salcedo
Isaac Salcedo - avatar
+ 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/
19th Oct 2018, 7:20 PM
Isaac Salcedo
Isaac Salcedo - avatar
0
Do you mean find a string that is contained in another string?
19th Oct 2018, 1:29 AM
Isaac Salcedo
Isaac Salcedo - avatar
0
yes
19th Oct 2018, 12:23 PM
NimaNA11
NimaNA11 - avatar
0
tank you vey much. can u explain me line 10. and is there any find function in strings?
19th Oct 2018, 4:02 PM
NimaNA11
NimaNA11 - avatar
0
thanx a lot
19th Oct 2018, 8:48 PM
NimaNA11
NimaNA11 - avatar
0
You're welcome!
19th Oct 2018, 9:06 PM
Isaac Salcedo
Isaac Salcedo - avatar