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