0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

boost replace

Posted at

概要

全て置き換える

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;
    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?