开发者

Replace a Substring of a String in Velocity Template Language

开发者 https://www.devze.com 2023-03-23 11:35 出处:网络
I want to replace 开发者_运维百科a part of a string in Velocity Template Language with another string.

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


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}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号