Main Contents

How To split/explode a std::string ?

Tags: , , ,

Given a std::string, for example “XXX_YYY_ZZZ”, how to explode it with “_” as separator ?

Using boost’s split function :
std::string str("XXX_YYY_ZZZ"); // The string to explode
std::vector<std::string> StrVec; // The container
split( StrVec, str, is_any_of("_") ); // StrVec == { "XXX","YYY","ZZZ" }

romain @ April 6, 2009

1 Comment

  1. romain April 8, 2009 @ 4:26 pm

    Another option is to read this page

Leave a comment


Feed