On Feb 9, 2010, at 5:58 PM, Matthias Vallentin wrote:
On Tue, Feb 09, 2010 at 02:00:10PM +0530, Lloyd wrote:
Is it possibleto tokenize a string based on a string delimiter?
Let str be the string to split and delim your delimiter. Then,
std::vectorstd::string result; boost::iter_split(result, str, boost::first_finder(delim));
Or case insensitive:
std::vectorstd::string result; boost::iter_split(result, str, boost::first_finder(delim, boost::is_iequal()));
Can anyone tell me why iter_split (and split, etc) requires a vector<string> to hold the results? (or, more generally, a container) Is there some technical reason why it doesn't take an output iterator as a parameter, so it could be called like this? std::vectorstd::string result; boost::iter_split ( std::back_inserter<string> (result), str, boost::first_finder(delim)); or even: boost::iter_split ( std::ostream_iteratorstd::string(std::cout, ", "), str, boost::first_finder(delim)); (thereby removing the (fixed) link between "iter_split" and "std::vectorstd::string") -- Marshall