I am trying to split sentences apart by punctuation (.
, ?
, !
). I have found on StackOverflow a way to separate a string by one delimiter, but I have not been able to find a way to separate a string based on multiple delimiters at once. Here is the code I have so far:
void chopSentences(std::string new_sentences, std::vector<std::string> sentences) {
size_t pos = 0;
std::string token;
std::string delimiter = ".";
while ((pos = new_sentences.find(delimiter) != std::string::npos)) {
token = new_sentences.substr(0, pos);
sentences.push_back(token);
new_sentences.erase(0, pos + delimiter.length());
}
}
Any idea on how to make it more than one delimiter?