単純な文字列の分割

 
 / **
*株式の分割文字列。
*
*分割する文字列を@param。
*区切り文字を@param。
*文字列の部分でベクトルを@returnsは分割しました。空の文字列が結果から削除されません。
* /
std ::ベクトル<はstd :: string>にsplit_string(のconstのstd ::文字列&src_str、constのchar型*でdelim)
{
    std ::ベクトル<はstd :: string>にトークン。
    もし(src_str.empty()|| nullptr ==でdelim)
        トークンを返します。
 
    size_tのdelim_len = STRLEN(DELIM)。
    std ::文字列:: size_type POS = 0;
    一方(POS <src_str.size())
    {
        std ::文字列:: size_type next_pos = src_str.find(DELIM、POS);
        もし(STD ::文字列:: NPO団体== next_pos)
            next_pos = src_str.size()。
 
        もし(POS <next_pos)
            tokens.push_back(src_str.substr(POS、next_pos  -  POS))。
 
        もし(POS == next_pos)
            tokens.push_back( "");
 
        POS = next_pos + delim_len。
    }
 
    トークンを返します。
}
 
 
 
 

おすすめ

転載: www.cnblogs.com/water-bear/p/12132746.html