Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用另一个字符串替换速度模板语言中字符串的一部分。
例如:
#set($a = "Hello") #set($b = "+")
我想用 ++ 替换 Hello 中的 ll。输出应该是 He++o
请帮我
谢谢基肖尔
默认情况下,您可以使用 Java String 对象的方法:
#set( $a = "Hello" ) #set( $b = $a.replace("l", "+") ) ${b}
将产生He++o,您还可以使用速度变量作为方法调用的参数,例如:
#set( $a = "Hello" ) #set( $b = "+" ) #set( $c = $a.replace("l", ${b}) ) ${c}