用 Velocity 模板语言替换字符串的子串 [英] Replace a Substring of a String in Velocity Template Language
本文介绍了用 Velocity 模板语言替换字符串的子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用另一个字符串替换 Velocity 模板语言中字符串的一部分.
I want to replace a part of a string in Velocity Template Language with another string.
例如:
#set($a = "Hello")
#set($b = "+")
我想用++替换Hello中的ll.输出应该是 He++o
I want to replace ll in Hello with ++. The output should be He++o
请帮帮我
谢谢基肖尔
推荐答案
默认情况下你可以使用 Java String 对象的方法:
By default you can use the methods of the Java String object:
#set( $a = "Hello" )
#set( $b = $a.replace("l", "+") )
${b}
将产生 He++o,您也可以使用速度变量作为方法调用的参数,例如:
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}
这篇关于用 Velocity 模板语言替换字符串的子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文