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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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
*/
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply