概要
全て置き換える
include
boost/algorithm/string/replace.hpp
Exmaple
// 破壊的な変更を行うバージョン
{
std::string s = "Hello Jane, Hello World!";
// 全ての"Hello"を"Goodbye"に置き換える
boost::algorithm::replace_all(s, "Hello", "Goodbye");
boost::algorithm::replace_all(s, "Goodbye", "Goodbye1");
std::cout << s << std::endl;
}
// コピーを返すバージョン
{
const std::string s = "Hello Jane, Hello World!";
const std::string result = boost::algorithm::replace_all_copy(s, "Hello", "Goodbye");
std::cout << result << std::endl;
}
// 先頭、最後
{
string str1 = "Hello Dolly, Hello World! Hello World!";
boost::algorithm::replace_all(str1, "Hello", "Bye");
std::cout << str1 << std::endl;
boost::algorithm::replace_first(str1, "Bye", "Bye1");
std::cout << str1 << std::endl;
boost::algorithm::replace_last(str1, "Bye", "Bye1");
std::cout << str1 << std::endl;
}