Extract word from string

I've never really spent the time getting into more string manipulation than I thought necessary so it's beginners forum section time.

Let's say I have a long string with any kind of character in it (including CRLF's). I want to grab a number out of it that's directly to the right (after a space) of a word.

I want the number that comes after 'theWord', which would be 9 in this string:

blablablablabla(
blabla(blablabla
blablablablablab
labla(theWord 9)
blablablablabla

There may be a variable amount of left parenthesis before the one just before 'theWord'.

What's the best function to use to get the number after the word?

You can find the "theWord " from the string in order to focus on the point, where the number supposedly is. Then you could make a stringstream from a substring and attempt to read a number from that stream.

C++11 has regular expressions, which could make the process more robust.
I think .find and .substr could be used here fairly easily.
Yep those two functions made it easy, thx.
Topic archived. No new replies allowed.