1

text=s_o_m_e=text文字列を次のように置き換えたいtext=s-o-m-e=text

開始インデックスと終了インデックスがあります。

std::string str("text=s_o_m_e=text");

std::string::size_type start = str.find("text="), end;

if (start != std::string::npos) {
    end = str.find("=", start);

    if (end != std::string::npos) {
        //...
    }
}

だから、私はこのような関数を探しています:

replaceAll(string, start, end, '_', '-');

上:

std::replace(str.begin() + start, str.begin() + end, '_', '-');

ありがとう、高炉

4

2 に答える 2

10

そのための機能があります<algorithm>

std::replace(str.begin(), str.end(), '_', '-');
于 2012-06-04T07:15:15.050 に答える
5

を使用しstd::replaceます。詳細はこちらです。

于 2012-06-04T07:16:40.820 に答える