Extract substring from string

Put this into Home Assistant’s Template Editor and experiment with it.

{% set x = "Friday" %}
{{ x[:3] }}

Result is: Fri

Example here:

Here’s a more complicated example:

{% set num = "8886758934" %}
{{ "("+num[:3]+") "+num[3:-4]+"-"+num[-4:] }}

Result is: (888) 675-8934

Here’s an explanation of “slice notation”:

10 Likes