I am working on project and i am almost finished but the last part of the assignment is to take the user input and remove all leading and trailing white space, so that when i prompt the user for an answer, the input would match if they had spaces before or after their answer.
For Example if the correct answer is small fry: The user could enter:___small fry___ and it would match.
__ is representing spaces for this instance.
c++ has a lot of good stuff but someone dropped the ball on having a trim in algorithms. you will have to write it yourself.
do you want to eliminate, collapse, or ignore internal whitespace?
eg "x y" vs "x y" vs "xy" ?
leading trailing is easy. loop front to back, find the first non whitespace char in the string, and save its location. Loop back to front, find first non whitespace char and keep that location too. Take substring of the middle part, from the 2 saved locations inclusive. (this can be done in a single loop, of course, but its not generally going to be worth the trouble).
So i understand what you are saying to do but im not exactly sure how to implement what you put with my already existing code. Could you get me started? Basically what I need is for when i enter the text for "userinput" i need it to take whatever i type and remove all leading and trailing whitespace for two words but leave the space in the middle.