From 8218e45cbcc756333bee6b6245ef5a4c2aaa273f Mon Sep 17 00:00:00 2001 From: James Nugent Date: Wed, 17 May 2017 20:48:12 -0400 Subject: Add "replaceAll" function and documentation This commit adds a `replaceAll` function which takes three arguments - an original string, the substring to replace, and the string with which to replace it. This is of particular use when generating node names from IP addresses where the node name may not contain "." characters. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 92b8085f..cb60f2c6 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Gomplate is an alternative that will let you process templates which also includ - [`slice`](#slice) - [`split`](#split) - [`splitN`](#splitn) + - [`replaceAll`](#replaceAll) - [`title`](#title) - [`toLower`](#tolower) - [`toUpper`](#toupper) @@ -355,6 +356,23 @@ $ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}{{end}}' foo bar:baz ``` +#### `replaceAll` + +Replaces all occurrences of a given string with another. + +##### Example + +```console +$ gomplate -i '{{ replaceAll "." "-" "172.21.1.42" }}' +172-21-1-42 +``` + +##### Example (with pipeline) + +```console +$ gomplate -i '{{ "172.21.1.42" | replaceAll "." "-" }}' +172-21-1-42 +``` #### `title` -- cgit v1.2.3