SO I have to split the phrase: "Hello, everyone! This is: COSC-1436, SP18" into separate tokens, dismissing any punctuation minus the dash. So the output should be:
Hello
everyone
This
is
COSC-1436
SP18
And I then must encrypt each token, which I got covered. I'm just having trouble using multiple delimiters. Here's what I have currently.
Function prototype:
void tokenize(const string&, const string&, vector<string>&);
Function call:
tokenize(code, " .,:;!?", tokens);
Function definition:
void tokenize(const string& str, const string& delim, vector<string>& tokens)
{
int tokenStart = 0;
int delimPos = str.find_first_of(delim);
while(delimPos != string::npos)
{
string tok = str.substr(tokenStart, delimPos - tokenStart);
tokens.push_back(tok);
delimPos++;
tokenStart = delimPos;
delimPos = str.find_first_of(delim, delimPos);
if(delimPos == string::npos)
{
string tok = str.substr(tokenStart, delimPos - tokenStart);
tokens.push_back(tok);
}
}
}
The only problem is that there are now tokens as blank spaces where the program encountered the punctuation marks. Any suggestions?