Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a Substring of a String in Velocity Template Language

I want to replace a part of a string in Velocity Template Language with another string.

For Example:

#set($a = "Hello") #set($b = "+") 

I want to replace ll in Hello with ++. The output should be He++o

Please help me

Thanks Kishore

like image 817
kishore Avatar asked Jul 27 '11 11:07

kishore


1 Answers

By default you can use the methods of the Java String object:

#set( $a = "Hello" ) #set( $b = $a.replace("l", "+") ) ${b} 

will produce He++o and you can also use velocity variables as arguments to your method calls, e.g.:

#set( $a = "Hello" ) #set( $b = "+" ) #set( $c = $a.replace("l", ${b}) ) ${c} 
like image 67
Mark McLaren Avatar answered Sep 29 '22 22:09

Mark McLaren