c++ Is there a way to find sentences within strings? -


i'm trying recognise phrases within user defined string far have been able single word. example, if have sentence:

"what think of stack overflow?"

is there way search "what you" within string?

i know can retrieve single word find function when attempting 3 gets stuck , can search first.

is there way search whole string in string?

use str.find()

size_t find (const string& str, size_t pos = 0) 

its return value starting position of substring. can test if string looking is contained in main string performing simple boolean test of returning str::npos:

string str = "what think of stack overflow?"; if (str.find("what you") != str::npos) // contained 

the second argument can used limit search string position.

the op question mentions gets stuck in attempt find 3 word string. actually, believe misinterpreting return value. happens return single word search "what" , string "what you" have coincidental starting positions, therefore str.find() returns same. search individual words positions, use multiple function calls.


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -