The function split()
is used to break down the value of a complex string variable into individual elements which can then be treated individually.
This allows you to iterate through complex string values, e.g., in a loop. Elements are broken down according to a specified pattern which serves as separator.
split(<string variable>, <pattern>)
Note
<pattern> may be a regular expression to find multiple separators (e.g., comma and semicolon) and complex separators (e.g., ---) at once.
To use a control character that is reserved in RegExp, e.g., the pipe symbol (|), as a separator, you have to double escape the character. For example:
#split(fo|o, '\\|')#
In the following example, the string value of variable foo is broken down into individual elements. Elements are separated by a comma. Each element (except the last) is then printed with a following <br>
tag:
<isset scope="request" name="lines" value="#split(foo, ',')#"> <isloop iterator="lines" alias="line"> <isprint value="#line#"> <isif condition="#hasNext(line)#"><br></isif> </isloop>