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