github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/substr.html.md (about) 1 --- 2 layout: "language" 3 page_title: "substr - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-string-substr" 5 description: |- 6 The substr function extracts a substring from a given string by offset and 7 length. 8 --- 9 10 # `substr` Function 11 12 `substr` extracts a substring from a given string by offset and length. 13 14 ```hcl 15 substr(string, offset, length) 16 ``` 17 18 ## Examples 19 20 ``` 21 > substr("hello world", 1, 4) 22 ello 23 ``` 24 25 The offset and length are both counted in _unicode characters_ rather than 26 bytes: 27 28 ``` 29 > substr("🤔🤷", 0, 1) 30 🤔 31 ``` 32 33 The offset index may be negative, in which case it is relative to the end of 34 the given string. The length may be -1, in which case the remainder of the 35 string after the given offset will be returned. 36 37 ``` 38 > substr("hello world", -5, -1) 39 world 40 ```