[#absl-StrReplaceAll-0ee] = xref:absl.adoc[absl]::StrReplaceAll :relfileprefix: ../ :mrdocs: Replaces character sequences within a given string with replacements provided within an initializer list of key/value pairs. == Synopsis Declared in `<absl/strings/str_replace.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] std::string StrReplaceAll( std::string_view s, std::initializer_list<std::pair<std::string_view, std::string_view>> replacements); ---- == Description Candidate replacements are considered in order as they occur within the string, with earlier matches taking precedence, and longer matches taking precedence for candidates starting at the same position in the string. Once a substitution is made, the replaced text is not considered for any further substitutions. Example: std::string s = absl::StrReplaceAll( "stem:[who bought ]count #Noun. Thanks $who!", {{"$count", absl::StrCat(5)}, {"$who", "Bob"}, {"#Noun", "Apples"}}); EXPECT_EQ("Bob bought 5 Apples. Thanks Bob!", s); == Return Value A new string with the replacements applied. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== == Parameters [cols="1,4"] |=== | Name| Description | *s* | The string to search for replacements. | *replacements* | The key/value pairs of sequences to replace. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#