puckerhoop
asked on
string search: specific word in string
Any suggestions on how to find a SPECIFIC word in a string?
ie. looking for "the"
in string: In the end, I figured it out.
ie. looking for "the"
in string: In the end, I figured it out.
notice that this will only find the FIRST occurence of "ello", to keep searching you've got to search not from 0 but from the end of the previous occurrence.
ASKER
In Unix, you can use
grep '^he.*'
To find an occurence beginning with "he", is there such way to do this is C++?
Any way to limit it to occurences of the specific word, ONLY? (only when it is solo or followed by punctuation).
I am going to need to replace the word... would it be better to use the string function for replace?
Tx!
grep '^he.*'
To find an occurence beginning with "he", is there such way to do this is C++?
Any way to limit it to occurences of the specific word, ONLY? (only when it is solo or followed by punctuation).
I am going to need to replace the word... would it be better to use the string function for replace?
Tx!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>pos < str.length() - 1
should be pos < str.length() ;D
should be pos < str.length() ;D
ASKER
what is 'D' (decrement?)
my compiler doesn't like it... does it need to be declared?
my compiler doesn't like it... does it need to be declared?
ASKER
Visual C++ 6.0 (compiler)
ASKER
maybe:
pos < str.max_size();
??
pos < str.max_size();
??
ASKER
Made some slight modification to work with my compiler!
THANKS!
THANKS!
puckerhoop, sorry I just got back from work. That's a smiley! :D
string x = "hello world";
string::size_type pos = x.find("ello", 0);