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