absl::StrReplaceAll

StrReplaceAll overloads

Synopses

Declared in <absl/strings/str_replace.h>

Replaces character sequences within a given string with replacements provided within an initializer list of key/value pairs.

[[nodiscard]]
std::string
StrReplaceAll(
    std::string_view s,
    std::initializer_list<std::pair<std::string_view, std::string_view>> replacements);
» more...

Overload of StrReplaceAll() to replace character sequences within a given output string in place with replacements provided within an initializer list of key/value pairs, returning the number of substitutions that occurred.

int
StrReplaceAll(
    std::initializer_list<std::pair<std::string_view, std::string_view>> replacements,
    std::string* target);
» more...

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.

template<typename StrToStrMapping>
std::string
StrReplaceAll(
    std::string_view s,
    StrToStrMapping const& replacements);
» more...

Overload of StrReplaceAll() to replace patterns within a given output string in place with replacements provided within a container of key/value pairs.

template<typename StrToStrMapping>
int
StrReplaceAll(
    StrToStrMapping const& replacements,
    std::string* target);
» more...

Return Value

  • A new string with the replacements applied.
  • The number of substitutions that occurred.

Parameters

NameDescription
sThe string to search for replacements.
replacementsThe key/value pairs of sequences to replace.
targetThe string to modify in place.