[#absl-StrReplaceAll-0c] = xref:absl.adoc[absl]::StrReplaceAll :relfileprefix: ../ :mrdocs: Overload of `StrReplaceAll()` to accept a container of key/value replacement pairs (typically either an associative map or a `std::vector` of `std::pair` elements). A vector of pairs is generally more efficient. == Synopsis Declared in `<absl/strings/str_replace.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename StrToStrMapping> std::string StrReplaceAll( std::string_view s, StrToStrMapping const& replacements); ---- == Description Examples: std::map<const absl::string_view, const absl::string_view> replacements; replacements["$who"] = "Bob";] replacements["$count"] = "5";] replacements["#Noun"]= "Apples"; std::string s = absl::StrReplaceAll( "stem:[who bought ]count #Noun. Thanks $who!", replacements); EXPECT_EQ("Bob bought 5 Apples. Thanks Bob!", s); // A std::vector of std::pair elements can be more efficient. std::vector<std::pair<const absl::string_view, std::string>> replacements; replacements.push_back({"&", "&amp;"}); replacements.push_back({"<", "&lt;"}); replacements.push_back({">", "&gt;"}); std::string s = absl::StrReplaceAll("if (ptr < &foo)", replacements); EXPECT_EQ("if (ptr &lt; &amp;foo)", s); == Return Value A new string with the replacements applied. == Parameters [cols="1,4"] |=== | Name| Description | *s* | The string to search for replacements. | *replacements* | The container of key/value pairs of sequences to replace. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#