I am working with velocity (in Polarion - don't know whether it matters). And I am trying to split a sting into pieces. But it does not seem to work.
#set ($myString ="This.is.my.dummy.text")
#set ($myArray = $myString.split('[.]'))
myString: $myString <br>
myString.class: $myString.class <br>
myArray: $myArray. <br>
myArray.class: $myArray.class <br>
myArray.length: $myArray.length() <br>
myArray.size: $myArray.size() <br>
myArray.get: $myArray.get(1) <br>
#foreach ($tmp in $myArray)
tmp: $tmp <br>
#end
The output of my code is this:
myString: This.is.my.dummy.text
myString.class: class java.lang.String
myArray: [Ljava.lang.String;@5f41d583.
myArray.class: class [Ljava.lang.String;
myArray.length: $myArray.length()
myArray.size: $myArray.size()
myArray.get: $myArray.get(1)
tmp: This
tmp: is
tmp: my
tmp: dummy
tmp: text
myArray seems to be correct. My Questions:
Thanks
Jenny
In Polarion Velocity you are severely limited as opposed to working in Java. To work in Polarion you may want to install the Wiki Scripting Extension, which introduces some very helpful objects into the Velocity scope: https://extensions.polarion.com/extensions/83-wiki-scripting-tools
This is a must-have for scripting in Polarion Velocity. You'll need these tools in many other instances as well.
Then you can write:
myArray.length: $listTool.size($myArray) <br>
myArray.get: $listTool.get($myArray, 1) <br>
Which results in:
myArray.length: 5
myArray.get: is