Page 1 of 1

I'm working on a parsing exercise for an OOP course. I need to parse a set of given strings so that leading and trailing

Posted: Thu May 05, 2022 12:58 pm
by answerhappygod
I'm working on a parsing exercise for an OOP course.
I need to parse a set of given strings so that leading and
trailing spaces are removed and each token outputs to a
newline.
(I'm including one string that is representative of the variety
of challenges)
And this function needs to be scalable to more or less
tokens.
int parseExercise(string str) {
string strCopy;
string emptyCompare;
// for loop , copy string
// while, compare to empty string
// if ' ' delimiter, truncate
// if "\"" delimiter, tokenize to substring
// if substring.length-1 == ' ', truncate
// cout substring
// truncate substring
// continue loop/truncate until strCopy == emptyCompare
}
int main() {
string str1 = " \"Painting For Sale \" \" Vincent Van Gogh\"
1870 \"Live Auction\" ";
parseExercise(str1);
/*
The function parseExercise() will display four tokens, all
nicely aligned:
Painting For Sale
Vincent Van Gogh
1870
Live Auction
*/