explode

Splits a string into an array of strings using the specified delimiter. This is typically used when you have a list of items separated by commas or spaces, and want to be able to iterate over them in a loop. An optional second parameter is the maximum number of results to return. If no limit is specified, all of the sub-strings will be returned.

{% set arr as  var|explode(',') %}
{% for item in var|explode(' ', 5) %}