I have an issue with extracting a substring in velocity. the string I have is 1M/1Y (the variable string here) I need to extract 1M and 1Y. what is the best way to do it?
#set($index=$string.index('/'))
#set($val=$string.substring($index,index+2))
what am I doing wrong here?
You can use stringUtil: #set($parts = $stringUtil. split($string, "/")) $parts.
Developer file used by Velocity, a Java-based template engine; written using the Velocity Template Language (VTL); contains VTL statements inserted in a normal text document; often used for auto-generating Web source code and class skeletons.
Velocity is a server-side template language used by Confluence to render page content. Velocity allows Java objects to be called alongside standard HTML. If you are are writing a user macro or developing a plugin you may need to modify Velocity content.
In velocity template we have access to all the public methods of the String class. Try using the below code
#set ($index = $string.indexOf('/'))
#set ($val1= $string.substring(0, $index))
#set ($index = $index + 1)
#set ($val2 = $string.substring($index))
or you can also make use of $string.split("/")
if you are using Velocity 1.7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With