From 474e4857bd79fefb45baccc10803c0ebdb541700 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Mon, 1 May 2017 21:01:55 -0400 Subject: Add splitN function (i.e. strings.SplitN) Signed-off-by: Dave Henderson --- README.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 027e2525..20ffa21e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ Gomplate is an alternative that will let you process templates which also includ - [Example](#example) - [`split`](#split) - [Example](#example) + - [`splitN`](#splitn) + - [Example](#example) - [`title`](#title) - [Example](#example) - [`toLower`](#tolower) @@ -361,20 +363,26 @@ Creates a slice by splitting a string on a given delimiter. Equivalent to ##### Example -_`input.tmpl`:_ -``` -{{range split "Bart,Lisa,Maggie"}} -Hello, {{.}} -{{- end}} -``` - ```console -$ gomplate < input.tmpl +$ gomplate -i '{{range split "Bart,Lisa,Maggie" ","}}Hello, {{.}}{{end}}' Hello, Bart Hello, Lisa Hello, Maggie ``` +#### `splitN` + +Creates a slice by splitting a string on a given delimiter. The count determines +the number of substrings to return. Equivalent to [strings.SplitN](https://golang.org/pkg/strings#SplitN) + +##### Example + +```console +$ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}{{end}}' +foo +bar:baz +``` + #### `title` Convert to title-case. Equivalent to [strings.Title](https://golang.org/pkg/strings/#Title) -- cgit v1.2.3