I was separating my string into words, but I came across an use case where some words will have to be broken into 3 words or more.
Example:
string userInput = "This is <b> Bold </b> text.";
string word;
vector<string> words;
for (stringstream s(userInput); s >> word;)
words.push_back(word);
This operation gets me what I want initially, however I also need to pay attention to cases like this:
string userInput = "This is <b>Bold</b> text.";
// <b>Bold</b> needs to be broken into 3 words.
I tried a few different things, like:
std::istringstream ss(userInput);
std::string token;
while( std::getline(ss, token, '>')) {
cout << token << endl; // to see how I'm breaking the words
}
but I'm getting getting this:
This is <b
Bold</b
text.
Any suggestions on an effective way to deal with this? Thanks
another example of string that will need to be separated:
<a>1<abbr>2<acronym>3<b>4<blockquote>5<cite>6<code>7<del><em><i><q><strike><strong>8</strong>9</strike>10</q>11</i>12</em></del></code></cite></blockquote></b></acronym></abbr></a>13
Aucun commentaire:
Enregistrer un commentaire