Split on substring

前端 未结 4 2015
天涯浪人
天涯浪人 2020-12-15 01:15

How would I split a string based on another substring in a simple way?

e.g. split on \"\\r\\n\"

message1\\r\\nmessage2 

=>

4条回答
  •  死守一世寂寞
    2020-12-15 01:52

    It's a huge dependency, but I personally like Boost::Tokenizer.

    From the example on the page:

    // simple_example_1.cpp
    #include
    #include
    #include
    
    int main(){
       using namespace std;
       using namespace boost;
       string s = "This is,  a test";
       tokenizer<> tok(s);
       for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
           cout << *beg << "\n";
       }
    }
    

提交回复
热议问题