Hi, I use boost::tokenizer for this problem. Example int split(std::vector<std::string>& list, const std::string& eingabe, const std::string& delims, bool keep_empty) { list.clear(); boost::empty_token_policy empty_tokens; if( keep_empty) empty_tokens = boost::keep_empty_tokens; else empty_tokens = boost::drop_empty_tokens; boost::char_separator<char> sep(delims.c_str(), "", empty_tokens); typedef boost::tokenizer<boost::char_separator<char> > tokenizer; tokenizer tokens(eingabe, sep); tokenizer::iterator tok_iter = tokens.begin(); for (; tok_iter != tokens.end(); ++tok_iter) list.push_back(*tok_iter); return list.size(); } //--------------------------------------------------------------------------- abir basak schrieb:
Hi, I want to tokenize a string based on one or multiple space or tab
std::string s = " a b c d \te "; std::vector<std::string> tokens; boost::algorithm::split(tokens,s,boost::algorithm::is_any_of(" \t"),token_compress_on); copy(tokens.begin(),tokens.end(),ostream_iterator<string>(cout,"\n"));
This gives more or less correct result, except it does not remove space/ tab from begin /end. It can be done like trim(s); and then call the above. But is there any other way it can be done in split itself ?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users