I HATE velocity and rarely ever use it but sometimes I am called upon at my job to do so. I can never really figure out just how to use it.
I have this
Without using StringUtils this can be done using the String split()
method.
Unlike it's Java counterpart for special characters one doesn't need to escape the forward slash (.e.g "\\|"
) as @kamcknig correctly stated:
#set ($myString = “This|is|my|dummy|text”)
#set ($myArray = $myString.split("\|")) or
#set ($myArray = $myString.split('\|')) or
#set ($myArray = $myString.split("[|]"))
Note 1: To get the size of the array use: $myArray.size()
Note 2: To get actual values use $myArray.get(0)
or $myArray[0]
… etc
Suggestion: one could use beforehand #if ($myString.indexOf(‘|’)) ... #end