How do I replace ";" with "," in string "Red; Green; Blue"?
{% set rgb = "Red; Green; Blue" %}
Twig has a replace filter for that. You can replace strings/vars with strings/vars:
{% set string = "I love apples" %}
{% set var = "like" %}
{% set string = string|replace({'apples': 'kiwis', 'love': var}) %}
{{ string }} {# Prints "I like kiwis" #}
Your example:
{% set rgb = "Red; Green; Blue" %}
{% set rgb = rgb|replace({';': ','}) %}
{{ rgb }} {# Prints "Red, Green, Blue" #}
|replace('apples', 'kiwis')
Commented
Jun 14, 2014 at 13:35