On Tue, Jan 29, 2013 at 2:24 PM, Neil Sutton
I am writing a very simple program that extracts numbers from a string. The numbers are actually lottery numbers. So far, my program connects to a certain url and downloads a file that contains the latest lottery results. I have managed to reach the point where the barest amount of relevant data is contained in a std::string.
I almost forgot, over a decade ago, I did write my own string splitter, similar to: void split(const string& str, const string& delimiters , vector<string>& tokens) { // Skip delimiters at beginning. string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". string::size_type pos = str.find_first_of(delimiters, lastPos); while (string::npos != pos || string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } } If you search, you will find this simple string splitter algorithm has been posted by several different people, and it is unknown to me whether those who did so copied material others had posted or developed it themselves (the algorithm itself is so simple and obvious it would not surprise me if many who considered the problem developed it independently. Back when I served as an educator, it would be something I'd have assigned a second year programming class to implement as one of the course's exercises; as a help in understanding the resources of STL and how to apply them in a common problem. Cheers Ted