I’ve got a little issue with my string::find implementation.
The input is a long string, which consist of this possible example: input = “one_thousand_and_fifty_one”.
My issue seems to be, that in an input string that contains more than one ‘and’, only the first and is removed, and the others aren’t.
This is my code so far, which finds “and”, but only removes is when the letter before ‘a’ isn’t ‘s’ (which indicates “thousand”).
string toKill = "and";
size_t andF = input.find(toKill);
if (andF != string::npos) {
if (input[(andF - 1)] != 's') {
input.erase(andF, 4);
}
}
EDIT: I forgot to mention, that the only other word in the input that contains ‘and’ is ‘thousand’, so this IS a special case.
Try this: