github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/docs/content/functions/strings.md (about)

     1  ---
     2  title: strings functions
     3  menu:
     4    main:
     5      parent: functions
     6  ---
     7  
     8  
     9  ## `strings.Abbrev`
    10  
    11  Abbreviates a string using `...` (ellipses). Takes an optional offset from the beginning of the string, and a maximum final width (including added ellipses).
    12  
    13  _Also see [`strings.Trunc`](#strings-trunc)._
    14  
    15  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
    16  ### Usage
    17  
    18  ```
    19  strings.Abbrev [offset] width input
    20  ```
    21  ```
    22  input | strings.Abbrev [offset] width
    23  ```
    24  
    25  ### Arguments
    26  
    27  | name | description |
    28  |------|-------------|
    29  | `offset` | _(optional)_ offset from the start of the string. Must be `4` or greater for ellipses to be added. Defaults to `0` |
    30  | `width` | _(required)_ the desired maximum final width of the string, including ellipses |
    31  | `input` | _(required)_ the input string to abbreviate |
    32  
    33  ### Examples
    34  
    35  ```console
    36  $ gomplate -i '{{ "foobarbazquxquux" | strings.Abbrev 9 }}'
    37  foobar...
    38  $ gomplate -i '{{ "foobarbazquxquux" | strings.Abbrev 6 9 }}'
    39  ...baz...
    40  ```
    41  
    42  ## `strings.Contains`
    43  
    44  Reports whether a substring is contained within a string.
    45  
    46  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
    47  ### Usage
    48  
    49  ```
    50  strings.Contains substr input
    51  ```
    52  ```
    53  input | strings.Contains substr
    54  ```
    55  
    56  ### Arguments
    57  
    58  | name | description |
    59  |------|-------------|
    60  | `substr` | _(required)_ the substring to search for |
    61  | `input` | _(required)_ the input to search |
    62  
    63  ### Examples
    64  
    65  _`input.tmpl`:_
    66  ```
    67  {{ if (.Env.FOO | strings.Contains "f") }}yes{{else}}no{{end}}
    68  ```
    69  
    70  ```console
    71  $ FOO=foo gomplate < input.tmpl
    72  yes
    73  $ FOO=bar gomplate < input.tmpl
    74  no
    75  ```
    76  
    77  ## `strings.HasPrefix`
    78  
    79  Tests whether a string begins with a certain prefix.
    80  
    81  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
    82  ### Usage
    83  
    84  ```
    85  strings.HasPrefix prefix input
    86  ```
    87  ```
    88  input | strings.HasPrefix prefix
    89  ```
    90  
    91  ### Arguments
    92  
    93  | name | description |
    94  |------|-------------|
    95  | `prefix` | _(required)_ the prefix to search for |
    96  | `input` | _(required)_ the input to search |
    97  
    98  ### Examples
    99  
   100  ```console
   101  $ URL=http://example.com gomplate -i '{{if .Env.URL | strings.HasPrefix "https"}}foo{{else}}bar{{end}}'
   102  bar
   103  $ URL=https://example.com gomplate -i '{{if .Env.URL | strings.HasPrefix "https"}}foo{{else}}bar{{end}}'
   104  foo
   105  ```
   106  
   107  ## `strings.HasSuffix`
   108  
   109  Tests whether a string ends with a certain suffix.
   110  
   111  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   112  ### Usage
   113  
   114  ```
   115  strings.HasSuffix suffix input
   116  ```
   117  ```
   118  input | strings.HasSuffix suffix
   119  ```
   120  
   121  ### Arguments
   122  
   123  | name | description |
   124  |------|-------------|
   125  | `suffix` | _(required)_ the suffix to search for |
   126  | `input` | _(required)_ the input to search |
   127  
   128  ### Examples
   129  
   130  _`input.tmpl`:_
   131  ```
   132  {{.Env.URL}}{{if not (.Env.URL | strings.HasSuffix ":80")}}:80{{end}}
   133  ```
   134  
   135  ```console
   136  $ URL=http://example.com gomplate < input.tmpl
   137  http://example.com:80
   138  ```
   139  
   140  ## `strings.Indent`
   141  
   142  **Alias:** `indent`
   143  
   144  Indents a string. If the input string has multiple lines, each line will be indented.
   145  
   146  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   147  ### Usage
   148  
   149  ```
   150  strings.Indent [width] [indent] input
   151  ```
   152  ```
   153  input | strings.Indent [width] [indent]
   154  ```
   155  
   156  ### Arguments
   157  
   158  | name | description |
   159  |------|-------------|
   160  | `width` | _(optional)_ number of times to repeat the `indent` string. Default: `1` |
   161  | `indent` | _(optional)_ the string to indent with. Default: `" "` |
   162  | `input` | _(required)_ the string to indent |
   163  
   164  ### Examples
   165  
   166  This function can be especially useful when adding YAML snippets into other YAML documents, where indentation is important:
   167  
   168  _`input.tmpl`:_
   169  ```
   170  foo:
   171  {{ `{"bar": {"baz": 2}}` | json | toYAML | strings.Indent "  " }}
   172  {{- `{"qux": true}` | json | toYAML | strings.Indent 2 }}
   173    quux:
   174  {{ `{"quuz": 42}` | json | toYAML | strings.Indent 2 "  " -}}
   175  ```
   176  
   177  ```console
   178  $ gomplate -f input.tmpl
   179  foo:
   180    bar:
   181      baz: 2
   182    qux: true
   183  
   184    quux:
   185      quuz: 42
   186  ```
   187  
   188  ## `strings.Sort` _(deprecated)_
   189  **Deprecation Notice:** Use [`coll.Sort`](../coll/#coll-sort) instead
   190  
   191  Returns an alphanumerically-sorted copy of a given string list.
   192  
   193  _Added in gomplate [v2.7.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.7.0)_
   194  ### Usage
   195  
   196  ```
   197  strings.Sort list
   198  ```
   199  ```
   200  list | strings.Sort
   201  ```
   202  
   203  ### Arguments
   204  
   205  | name | description |
   206  |------|-------------|
   207  | `list` | _(required)_ The list to sort |
   208  
   209  ### Examples
   210  
   211  ```console
   212  $ gomplate -i '{{ (coll.Slice "foo" "bar" "baz") | strings.Sort }}'
   213  [bar baz foo]
   214  ```
   215  
   216  ## `strings.SkipLines`_(unreleased)_
   217  **Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
   218  
   219  Skips the given number of lines (each ending in a `\n`), returning the
   220  remainder.
   221  
   222  If `skip` is greater than the number of lines in `in`, an empty string is
   223  returned.
   224  
   225  ### Usage
   226  
   227  ```
   228  strings.SkipLines skip in
   229  ```
   230  ```
   231  in | strings.SkipLines skip
   232  ```
   233  
   234  ### Arguments
   235  
   236  | name | description |
   237  |------|-------------|
   238  | `skip` | _(required)_ the number of lines to skip - must be a positive number |
   239  | `in` | _(required)_ the input string |
   240  
   241  ### Examples
   242  
   243  ```console
   244  $ gomplate -i '{{ "foo\nbar\nbaz" | strings.SkipLines 2 }}'
   245  baz
   246  ```
   247  ```console
   248  $ gomplate -i '{{ strings.SkipLines 1 "foo\nbar\nbaz" }}'
   249  bar
   250  baz
   251  ```
   252  
   253  ## `strings.Split`
   254  
   255  _Not to be confused with [`split`](#split), which is deprecated._
   256  
   257  Slices `input` into the substrings separated by `separator`, returning a
   258  slice of the substrings between those separators. If `input` does not
   259  contain `separator` and `separator` is not empty, returns a single-element
   260  slice whose only element is `input`.
   261  
   262  If `separator` is empty, it will split after each UTF-8 sequence. If
   263  both inputs are empty (i.e. `strings.Split "" ""`), it will return an
   264  empty slice.
   265  
   266  This is equivalent to [`strings.SplitN`](#strings-splitn) with a `count`
   267  of `-1`.
   268  
   269  Note that the delimiter is not included in the resulting elements.
   270  
   271  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   272  ### Usage
   273  
   274  ```
   275  strings.Split separator input
   276  ```
   277  ```
   278  input | strings.Split separator
   279  ```
   280  
   281  ### Arguments
   282  
   283  | name | description |
   284  |------|-------------|
   285  | `separator` | _(required)_ the delimiter to split on, can be multiple characters |
   286  | `input` | _(required)_ the input string |
   287  
   288  ### Examples
   289  
   290  ```console
   291  $ gomplate -i '{{range ("Bart,Lisa,Maggie" | strings.Split ",") }}Hello, {{.}}
   292  {{end}}'
   293  Hello, Bart
   294  Hello, Lisa
   295  Hello, Maggie
   296  ```
   297  ```console
   298  $ gomplate -i '{{range strings.Split "," "One,Two,Three" }}{{.}}{{"\n"}}{{end}}'
   299  One
   300  Two
   301  Three
   302  ```
   303  
   304  ## `strings.SplitN`
   305  
   306  _Not to be confused with [`splitN`](#splitn), which is deprecated._
   307  
   308  Slices `input` into the substrings separated by `separator`, returning a
   309  slice of the substrings between those separators. If `input` does not
   310  contain `separator` and `separator` is not empty, returns a single-element
   311  slice whose only element is `input`.
   312  
   313  The `count` determines the number of substrings to return:
   314  
   315  * `count > 0`: at most `count` substrings; the last substring will be the
   316    unsplit remainder.
   317  * `count == 0`: the result is nil (zero substrings)
   318  * `count < 0`: all substrings
   319  
   320  See [`strings.Split`](#strings-split) for more details.
   321  
   322  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   323  ### Usage
   324  
   325  ```
   326  strings.SplitN separator count input
   327  ```
   328  ```
   329  input | strings.SplitN separator count
   330  ```
   331  
   332  ### Arguments
   333  
   334  | name | description |
   335  |------|-------------|
   336  | `separator` | _(required)_ the delimiter to split on, can be multiple characters |
   337  | `count` | _(required)_ the maximum number of substrings to return |
   338  | `input` | _(required)_ the input string |
   339  
   340  ### Examples
   341  
   342  ```console
   343  $ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}
   344  {{end}}'
   345  foo
   346  bar:baz
   347  ```
   348  
   349  ## `strings.Quote`
   350  
   351  **Alias:** `quote`
   352  
   353  Surrounds an input string with double-quote characters (`"`). If the input is not a string, converts first.
   354  
   355  `"` characters in the input are first escaped with a `\` character.
   356  
   357  This is a convenience function which is equivalent to:
   358  
   359  ```
   360  {{ print "%q" "input string" }}
   361  ```
   362  
   363  _Added in gomplate [v3.1.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.1.0)_
   364  ### Usage
   365  
   366  ```
   367  strings.Quote in
   368  ```
   369  ```
   370  in | strings.Quote
   371  ```
   372  
   373  ### Arguments
   374  
   375  | name | description |
   376  |------|-------------|
   377  | `in` | _(required)_ The input to quote |
   378  
   379  ### Examples
   380  
   381  ```console
   382  $ gomplate -i '{{ "in" | quote }}'
   383  "in"
   384  $ gomplate -i '{{ strings.Quote 500 }}'
   385  "500"
   386  ```
   387  
   388  ## `strings.Repeat`
   389  
   390  Returns a new string consisting of `count` copies of the input string.
   391  
   392  It errors if `count` is negative or if the length of `input` multiplied by `count` overflows.
   393  
   394  This wraps Go's [`strings.Repeat`](https://golang.org/pkg/strings/#Repeat).
   395  
   396  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
   397  ### Usage
   398  
   399  ```
   400  strings.Repeat count input
   401  ```
   402  ```
   403  input | strings.Repeat count
   404  ```
   405  
   406  ### Arguments
   407  
   408  | name | description |
   409  |------|-------------|
   410  | `count` | _(required)_ the number of times to repeat the input |
   411  | `input` | _(required)_ the input to repeat |
   412  
   413  ### Examples
   414  
   415  ```console
   416  $ gomplate -i '{{ "hello " | strings.Repeat 5 }}'
   417  hello hello hello hello hello
   418  ```
   419  
   420  ## `strings.ReplaceAll`
   421  
   422  **Alias:** `replaceAll`
   423  
   424  Replaces all occurrences of a given string with another.
   425  
   426  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   427  ### Usage
   428  
   429  ```
   430  strings.ReplaceAll old new input
   431  ```
   432  ```
   433  input | strings.ReplaceAll old new
   434  ```
   435  
   436  ### Arguments
   437  
   438  | name | description |
   439  |------|-------------|
   440  | `old` | _(required)_ the text to replace |
   441  | `new` | _(required)_ the new text to replace with |
   442  | `input` | _(required)_ the input to modify |
   443  
   444  ### Examples
   445  
   446  ```console
   447  $ gomplate -i '{{ strings.ReplaceAll "." "-" "172.21.1.42" }}'
   448  172-21-1-42
   449  $ gomplate -i '{{ "172.21.1.42" | strings.ReplaceAll "." "-" }}'
   450  172-21-1-42
   451  ```
   452  
   453  ## `strings.Slug`
   454  
   455  Creates a a "slug" from a given string - supports Unicode correctly. This wraps the [github.com/gosimple/slug](https://github.com/gosimple/slug) package. See [the github.com/gosimple/slug docs](https://godoc.org/github.com/gosimple/slug) for more information.
   456  
   457  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
   458  ### Usage
   459  
   460  ```
   461  strings.Slug input
   462  ```
   463  ```
   464  input | strings.Slug
   465  ```
   466  
   467  ### Arguments
   468  
   469  | name | description |
   470  |------|-------------|
   471  | `input` | _(required)_ the input to "slugify" |
   472  
   473  ### Examples
   474  
   475  ```console
   476  $ gomplate -i '{{ "Hello, world!" | strings.Slug }}'
   477  hello-world
   478  ```
   479  ```console
   480  $ echo 'Rock & Roll @ Cafe Wha?' | gomplate -d in=stdin: -i '{{ strings.Slug (include "in") }}'
   481  rock-and-roll-at-cafe-wha
   482  ```
   483  
   484  ## `strings.ShellQuote`
   485  
   486  **Alias:** `shellQuote`
   487  
   488  Given a string, emits a version of that string that will evaluate to its literal data when expanded by any POSIX-compliant shell.
   489  
   490  Given an array or slice, emit a single string which will evaluate to a series of shell words, one per item in that array or slice.
   491  
   492  _Added in gomplate [v3.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.6.0)_
   493  ### Usage
   494  
   495  ```
   496  strings.ShellQuote in
   497  ```
   498  ```
   499  in | strings.ShellQuote
   500  ```
   501  
   502  ### Arguments
   503  
   504  | name | description |
   505  |------|-------------|
   506  | `in` | _(required)_ The input to quote |
   507  
   508  ### Examples
   509  
   510  ```console
   511  $ gomplate -i "{{ coll.Slice \"one word\" \"foo='bar baz'\" | shellQuote }}"
   512  'one word' 'foo='"'"'bar baz'"'"''
   513  ```
   514  ```console
   515  $ gomplate -i "{{ strings.ShellQuote \"it's a banana\" }}"
   516  'it'"'"'s a banana'
   517  ```
   518  
   519  ## `strings.Squote`
   520  
   521  **Alias:** `squote`
   522  
   523  Surrounds an input string with a single-quote (apostrophe) character (`'`). If the input is not a string, converts first.
   524  
   525  `'` characters in the input are first escaped in the YAML-style (by repetition: `''`).
   526  
   527  _Added in gomplate [v3.1.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.1.0)_
   528  ### Usage
   529  
   530  ```
   531  strings.Squote in
   532  ```
   533  ```
   534  in | strings.Squote
   535  ```
   536  
   537  ### Arguments
   538  
   539  | name | description |
   540  |------|-------------|
   541  | `in` | _(required)_ The input to quote |
   542  
   543  ### Examples
   544  
   545  ```console
   546  $ gomplate -i '{{ "in" | squote }}'
   547  'in'
   548  ```
   549  ```console
   550  $ gomplate -i "{{ strings.Squote \"it's a banana\" }}"
   551  'it''s a banana'
   552  ```
   553  
   554  ## `strings.Title`
   555  
   556  **Alias:** `title`
   557  
   558  Convert to title-case.
   559  
   560  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   561  ### Usage
   562  
   563  ```
   564  strings.Title input
   565  ```
   566  ```
   567  input | strings.Title
   568  ```
   569  
   570  ### Arguments
   571  
   572  | name | description |
   573  |------|-------------|
   574  | `input` | _(required)_ the input |
   575  
   576  ### Examples
   577  
   578  ```console
   579  $ gomplate -i '{{strings.Title "hello, world!"}}'
   580  Hello, World!
   581  ```
   582  
   583  ## `strings.ToLower`
   584  
   585  **Alias:** `toLower`
   586  
   587  Convert to lower-case.
   588  
   589  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   590  ### Usage
   591  
   592  ```
   593  strings.ToLower input
   594  ```
   595  ```
   596  input | strings.ToLower
   597  ```
   598  
   599  ### Arguments
   600  
   601  | name | description |
   602  |------|-------------|
   603  | `input` | _(required)_ the input |
   604  
   605  ### Examples
   606  
   607  ```console
   608  $ echo '{{strings.ToLower "HELLO, WORLD!"}}' | gomplate
   609  hello, world!
   610  ```
   611  
   612  ## `strings.ToUpper`
   613  
   614  **Alias:** `toUpper`
   615  
   616  Convert to upper-case.
   617  
   618  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   619  ### Usage
   620  
   621  ```
   622  strings.ToUpper input
   623  ```
   624  ```
   625  input | strings.ToUpper
   626  ```
   627  
   628  ### Arguments
   629  
   630  | name | description |
   631  |------|-------------|
   632  | `input` | _(required)_ the input |
   633  
   634  ### Examples
   635  
   636  ```console
   637  $ gomplate -i '{{strings.ToUpper "hello, world!"}}'
   638  HELLO, WORLD!
   639  ```
   640  
   641  ## `strings.Trim`
   642  
   643  Trims a string by removing the given characters from the beginning and end of
   644  the string.
   645  
   646  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   647  ### Usage
   648  
   649  ```
   650  strings.Trim cutset input
   651  ```
   652  ```
   653  input | strings.Trim cutset
   654  ```
   655  
   656  ### Arguments
   657  
   658  | name | description |
   659  |------|-------------|
   660  | `cutset` | _(required)_ the set of characters to cut |
   661  | `input` | _(required)_ the input |
   662  
   663  ### Examples
   664  
   665  ```console
   666  $ gomplate -i '{{ "_-foo-_" | strings.Trim "_-" }}
   667  foo
   668  ```
   669  
   670  ## `strings.TrimPrefix`
   671  
   672  Returns a string without the provided leading prefix string, if the prefix is present.
   673  
   674  This wraps Go's [`strings.TrimPrefix`](https://golang.org/pkg/strings/#TrimPrefix).
   675  
   676  _Added in gomplate [v2.5.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.5.0)_
   677  ### Usage
   678  
   679  ```
   680  strings.TrimPrefix prefix input
   681  ```
   682  ```
   683  input | strings.TrimPrefix prefix
   684  ```
   685  
   686  ### Arguments
   687  
   688  | name | description |
   689  |------|-------------|
   690  | `prefix` | _(required)_ the prefix to trim |
   691  | `input` | _(required)_ the input |
   692  
   693  ### Examples
   694  
   695  ```console
   696  $ gomplate -i '{{ "hello, world" | strings.TrimPrefix "hello, " }}'
   697  world
   698  ```
   699  
   700  ## `strings.TrimSpace`
   701  
   702  **Alias:** `trimSpace`
   703  
   704  Trims a string by removing whitespace from the beginning and end of
   705  the string.
   706  
   707  _Added in gomplate [v1.9.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.9.0)_
   708  ### Usage
   709  
   710  ```
   711  strings.TrimSpace input
   712  ```
   713  ```
   714  input | strings.TrimSpace
   715  ```
   716  
   717  ### Arguments
   718  
   719  | name | description |
   720  |------|-------------|
   721  | `input` | _(required)_ the input |
   722  
   723  ### Examples
   724  
   725  ```console
   726  $ gomplate -i '{{ "  \n\t foo" | strings.TrimSpace }}'
   727  foo
   728  ```
   729  
   730  ## `strings.TrimSuffix`
   731  
   732  Returns a string without the provided trailing suffix string, if the suffix is present.
   733  
   734  This wraps Go's [`strings.TrimSuffix`](https://golang.org/pkg/strings/#TrimSuffix).
   735  
   736  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
   737  ### Usage
   738  
   739  ```
   740  strings.TrimSuffix suffix input
   741  ```
   742  ```
   743  input | strings.TrimSuffix suffix
   744  ```
   745  
   746  ### Arguments
   747  
   748  | name | description |
   749  |------|-------------|
   750  | `suffix` | _(required)_ the suffix to trim |
   751  | `input` | _(required)_ the input |
   752  
   753  ### Examples
   754  
   755  ```console
   756  $ gomplate -i '{{ "hello, world" | strings.TrimSuffix "world" }}jello'
   757  hello, jello
   758  ```
   759  
   760  ## `strings.Trunc`
   761  
   762  Returns a string truncated to the given length.
   763  
   764  _Also see [`strings.Abbrev`](#strings-abbrev)._
   765  
   766  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
   767  ### Usage
   768  
   769  ```
   770  strings.Trunc length input
   771  ```
   772  ```
   773  input | strings.Trunc length
   774  ```
   775  
   776  ### Arguments
   777  
   778  | name | description |
   779  |------|-------------|
   780  | `length` | _(required)_ the maximum length of the output |
   781  | `input` | _(required)_ the input |
   782  
   783  ### Examples
   784  
   785  ```console
   786  $ gomplate -i '{{ "hello, world" | strings.Trunc 5 }}'
   787  hello
   788  ```
   789  
   790  ## `strings.CamelCase`
   791  
   792  Converts a sentence to CamelCase, i.e. `The quick brown fox` becomes `TheQuickBrownFox`.
   793  
   794  All non-alphanumeric characters are stripped, and the beginnings of words are upper-cased. If the input begins with a lower-case letter, the result will also begin with a lower-case letter.
   795  
   796  See [CamelCase on Wikipedia](https://en.wikipedia.org/wiki/Camel_case) for more details.
   797  
   798  _Added in gomplate [v3.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.3.0)_
   799  ### Usage
   800  
   801  ```
   802  strings.CamelCase in
   803  ```
   804  ```
   805  in | strings.CamelCase
   806  ```
   807  
   808  ### Arguments
   809  
   810  | name | description |
   811  |------|-------------|
   812  | `in` | _(required)_ The input |
   813  
   814  ### Examples
   815  
   816  ```console
   817  $ gomplate -i '{{ "Hello, World!" | strings.CamelCase }}'
   818  HelloWorld
   819  ```
   820  ```console
   821  $ gomplate -i '{{ "hello jello" | strings.CamelCase }}'
   822  helloJello
   823  ```
   824  
   825  ## `strings.SnakeCase`
   826  
   827  Converts a sentence to snake_case, i.e. `The quick brown fox` becomes `The_quick_brown_fox`.
   828  
   829  All non-alphanumeric characters are stripped, and spaces are replaced with an underscore (`_`). If the input begins with a lower-case letter, the result will also begin with a lower-case letter.
   830  
   831  See [Snake Case on Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details.
   832  
   833  _Added in gomplate [v3.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.3.0)_
   834  ### Usage
   835  
   836  ```
   837  strings.SnakeCase in
   838  ```
   839  ```
   840  in | strings.SnakeCase
   841  ```
   842  
   843  ### Arguments
   844  
   845  | name | description |
   846  |------|-------------|
   847  | `in` | _(required)_ The input |
   848  
   849  ### Examples
   850  
   851  ```console
   852  $ gomplate -i '{{ "Hello, World!" | strings.SnakeCase }}'
   853  Hello_world
   854  ```
   855  ```console
   856  $ gomplate -i '{{ "hello jello" | strings.SnakeCase }}'
   857  hello_jello
   858  ```
   859  
   860  ## `strings.KebabCase`
   861  
   862  Converts a sentence to kebab-case, i.e. `The quick brown fox` becomes `The-quick-brown-fox`.
   863  
   864  All non-alphanumeric characters are stripped, and spaces are replaced with a hyphen (`-`). If the input begins with a lower-case letter, the result will also begin with a lower-case letter.
   865  
   866  See [Kebab Case on Wikipedia](https://en.wikipedia.org/wiki/Kebab_case) for more details.
   867  
   868  _Added in gomplate [v3.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.3.0)_
   869  ### Usage
   870  
   871  ```
   872  strings.KebabCase in
   873  ```
   874  ```
   875  in | strings.KebabCase
   876  ```
   877  
   878  ### Arguments
   879  
   880  | name | description |
   881  |------|-------------|
   882  | `in` | _(required)_ The input |
   883  
   884  ### Examples
   885  
   886  ```console
   887  $ gomplate -i '{{ "Hello, World!" | strings.KebabCase }}'
   888  Hello-world
   889  ```
   890  ```console
   891  $ gomplate -i '{{ "hello jello" | strings.KebabCase }}'
   892  hello-jello
   893  ```
   894  
   895  ## `strings.WordWrap`
   896  
   897  Inserts new line breaks into the input string so it ends up with lines that are at most `width` characters wide.
   898  
   899  The line-breaking algorithm is _naïve_ and _greedy_: lines are only broken between words (i.e. on whitespace characters), and no effort is made to "smooth" the line endings.
   900  
   901  When words that are longer than the desired width are encountered (e.g. long URLs), they are not broken up. Correctness is valued above line length.
   902  
   903  The line-break sequence defaults to `\n` (i.e. the LF/Line Feed character), regardless of OS.
   904  
   905  _Added in gomplate [v3.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.3.0)_
   906  ### Usage
   907  
   908  ```
   909  strings.WordWrap [width] [lbseq] in
   910  ```
   911  ```
   912  in | strings.WordWrap [width] [lbseq]
   913  ```
   914  
   915  ### Arguments
   916  
   917  | name | description |
   918  |------|-------------|
   919  | `width` | _(optional)_ The desired maximum line length (number of characters - defaults to `80`) |
   920  | `lbseq` | _(optional)_ The line-break sequence to use (defaults to `\n`) |
   921  | `in` | _(required)_ The input |
   922  
   923  ### Examples
   924  
   925  ```console
   926  $ gomplate -i '{{ "Hello, World!" | strings.WordWrap 7 }}'
   927  Hello,
   928  World!
   929  ```
   930  ```console
   931  $ gomplate -i '{{ strings.WordWrap 20 "\\\n" "a string with a long url http://example.com/a/very/long/url which should not be broken" }}'
   932  a string with a long
   933  url
   934  http://example.com/a/very/long/url
   935  which should not be
   936  broken
   937  ```
   938  
   939  ## `strings.RuneCount`
   940  
   941  Return the number of _runes_ (Unicode code-points) contained within the
   942  input. This is similar to the built-in `len` function, but `len` counts
   943  the length in _bytes_. The length of an input containing multi-byte
   944  code-points should therefore be measured with `strings.RuneCount`.
   945  
   946  Inputs will first be converted to strings, and multiple inputs are
   947  concatenated.
   948  
   949  This wraps Go's [`utf8.RuneCountInString`](https://golang.org/pkg/unicode/utf8/#RuneCountInString)
   950  function.
   951  
   952  _Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
   953  ### Usage
   954  
   955  ```
   956  strings.RuneCount input
   957  ```
   958  ```
   959  input | strings.RuneCount
   960  ```
   961  
   962  ### Arguments
   963  
   964  | name | description |
   965  |------|-------------|
   966  | `input` | _(required)_ the input(s) to measure |
   967  
   968  ### Examples
   969  
   970  ```console
   971  $ gomplate -i '{{ range (coll.Slice "\u03a9" "\u0030" "\u1430") }}{{ printf "%s is %d bytes and %d runes\n" . (len .) (strings.RuneCount .) }}{{ end }}'
   972  Ω is 2 bytes and 1 runes
   973  0 is 1 bytes and 1 runes
   974  ᐰ is 3 bytes and 1 runes
   975  ```
   976  
   977  ## `contains` _(deprecated)_
   978  **Deprecation Notice:** Use [`strings.Contains`](#strings-contains) instead
   979  
   980  **See [`strings.Contains`](#strings-contains) for a pipeline-compatible version**
   981  
   982  Contains reports whether the second string is contained within the first. Equivalent to
   983  [strings.Contains](https://golang.org/pkg/strings#Contains)
   984  
   985  _Added in gomplate [v1.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.4.0)_
   986  ### Usage
   987  
   988  ```
   989  contains input substring
   990  ```
   991  
   992  ### Arguments
   993  
   994  | name | description |
   995  |------|-------------|
   996  | `input` | _(required)_ the string to search |
   997  | `substring` | _(required)_ the string to search for |
   998  
   999  ### Examples
  1000  
  1001  _`input.tmpl`:_
  1002  ```
  1003  {{if contains .Env.FOO "f"}}yes{{else}}no{{end}}
  1004  ```
  1005  
  1006  ```console
  1007  $ FOO=foo gomplate < input.tmpl
  1008  yes
  1009  $ FOO=bar gomplate < input.tmpl
  1010  no
  1011  ```
  1012  
  1013  ## `hasPrefix` _(deprecated)_
  1014  **Deprecation Notice:** Use [`strings.HasPrefix`](#strings-hasprefix) instead
  1015  
  1016  **See [`strings.HasPrefix`](#strings-hasprefix) for a pipeline-compatible version**
  1017  
  1018  Tests whether the string begins with a certain substring. Equivalent to
  1019  [strings.HasPrefix](https://golang.org/pkg/strings#HasPrefix)
  1020  
  1021  _Added in gomplate [v1.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.4.0)_
  1022  ### Usage
  1023  
  1024  ```
  1025  hasPrefix input prefix
  1026  ```
  1027  
  1028  ### Arguments
  1029  
  1030  | name | description |
  1031  |------|-------------|
  1032  | `input` | _(required)_ the string to search |
  1033  | `prefix` | _(required)_ the prefix to search for |
  1034  
  1035  ### Examples
  1036  
  1037  _`input.tmpl`:_
  1038  ```
  1039  {{if hasPrefix .Env.URL "https"}}foo{{else}}bar{{end}}
  1040  ```
  1041  
  1042  ```console
  1043  $ URL=http://example.com gomplate < input.tmpl
  1044  bar
  1045  $ URL=https://example.com gomplate < input.tmpl
  1046  foo
  1047  ```
  1048  
  1049  ## `hasSuffix` _(deprecated)_
  1050  **Deprecation Notice:** Use [`strings.HasSuffix`](#strings-hassuffix) instead
  1051  
  1052  **See [`strings.HasSuffix`](#strings-hassuffix) for a pipeline-compatible version**
  1053  
  1054  Tests whether the string ends with a certain substring. Equivalent to
  1055  [strings.HasSuffix](https://golang.org/pkg/strings#HasSuffix)
  1056  
  1057  _Added in gomplate [v1.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.4.0)_
  1058  ### Usage
  1059  
  1060  ```
  1061  hasSuffix input suffix
  1062  ```
  1063  
  1064  ### Arguments
  1065  
  1066  | name | description |
  1067  |------|-------------|
  1068  | `input` | _(required)_ the input to search |
  1069  | `suffix` | _(required)_ the suffix to search for |
  1070  
  1071  ### Examples
  1072  
  1073  _`input.tmpl`:_
  1074  ```
  1075  {{.Env.URL}}{{if not (hasSuffix .Env.URL ":80")}}:80{{end}}
  1076  ```
  1077  
  1078  ```console
  1079  $ URL=http://example.com gomplate < input.tmpl
  1080  http://example.com:80
  1081  ```
  1082  
  1083  ## `split` _(deprecated)_
  1084  **Deprecation Notice:** Use [`strings.Split`](#strings-split) instead
  1085  
  1086  **See [`strings.Split`](#strings-split) for a pipeline-compatible version**
  1087  
  1088  Creates a slice by splitting a string on a given delimiter. Equivalent to
  1089  [strings.Split](https://golang.org/pkg/strings#Split)
  1090  
  1091  _Added in gomplate [v1.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.4.0)_
  1092  ### Usage
  1093  
  1094  ```
  1095  split input separator
  1096  ```
  1097  
  1098  ### Arguments
  1099  
  1100  | name | description |
  1101  |------|-------------|
  1102  | `input` | _(required)_ the input string |
  1103  | `separator` | _(required)_ the string sequence to split |
  1104  
  1105  ### Examples
  1106  
  1107  ```console
  1108  $ gomplate -i '{{range split "Bart,Lisa,Maggie" ","}}Hello, {{.}}
  1109  {{end}}'
  1110  Hello, Bart
  1111  Hello, Lisa
  1112  Hello, Maggie
  1113  ```
  1114  
  1115  ## `splitN` _(deprecated)_
  1116  **Deprecation Notice:** Use [`strings.SplitN`](#strings-splitn) instead
  1117  
  1118  **See [`strings.SplitN`](#strings-splitn) for a pipeline-compatible version**
  1119  
  1120  Creates a slice by splitting a string on a given delimiter. The count determines
  1121  the number of substrings to return. Equivalent to [strings.SplitN](https://golang.org/pkg/strings#SplitN)
  1122  
  1123  _Added in gomplate [v1.7.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.7.0)_
  1124  ### Usage
  1125  
  1126  ```
  1127  splitN input separator count
  1128  ```
  1129  
  1130  ### Arguments
  1131  
  1132  | name | description |
  1133  |------|-------------|
  1134  | `input` | _(required)_ the input string |
  1135  | `separator` | _(required)_ the string sequence to split |
  1136  | `count` | _(required)_ the maximum number of substrings to return |
  1137  
  1138  ### Examples
  1139  
  1140  ```console
  1141  $ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}
  1142  {{end}}'
  1143  foo
  1144  bar:baz
  1145  ```
  1146  
  1147  ## `trim` _(deprecated)_
  1148  **Deprecation Notice:** Use [`strings.Trim`](#strings-trim) instead
  1149  
  1150  **See [`strings.Trim`](#strings-trim) for a pipeline-compatible version**
  1151  
  1152  Trims a string by removing the given characters from the beginning and end of
  1153  the string. Equivalent to [strings.Trim](https://golang.org/pkg/strings/#Trim)
  1154  
  1155  _Added in gomplate [v1.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.4.0)_
  1156  ### Usage
  1157  
  1158  ```
  1159  trim input cutset
  1160  ```
  1161  
  1162  ### Arguments
  1163  
  1164  | name | description |
  1165  |------|-------------|
  1166  | `input` | _(required)_ the input |
  1167  | `cutset` | _(required)_ the set of characters to cut |
  1168  
  1169  ### Examples
  1170  
  1171  _`input.tmpl`:_
  1172  ```
  1173  Hello, {{trim .Env.FOO " "}}!
  1174  ```
  1175  
  1176  ```console
  1177  $ FOO="  world " | gomplate < input.tmpl
  1178  Hello, world!
  1179  ```