Brad Borch
Brad Borch

Reputation: 319

cast string as array in Velocity template engine?

I have a form in Liferay, accessing data from an option field in Velocity returns a string in the form ["Boston","Denver","Detroit"]. But I can't treat it as an array per the documentation, if I do $array.length() I get the actual string length. Is there some command to cast as an array or do I have to parse the string?

Upvotes: 0

Views: 899

Answers (1)

Daniele Baggio
Daniele Baggio

Reputation: 2257

Use the stringUtil utility in velocity:

#set ($temp1= $stringUtil.replace($varString, '\"', ''))

#set ($varArray= $stringUtil.split($temp1, ','))

p.s. i'm not sure of sintax, please check it out

Upvotes: 0

Related Questions