替换 Ant 属性中的字符 [英] Replacing characters in Ant property
问题描述
是否有一种简单的方法可以获取一个属性的值,然后将其复制到另一个替换了某些字符的属性中?
Is there a simple way of taking the value of a property and then copy it to another property with certain characters replaced?
说propA=这是一个值
.我想将其中的所有空格替换为下划线,从而得到 propB=This_is_a_value
.
Say propA=This is a value
. I want to replace all the spaces in it into underscores, resulting in propB=This_is_a_value
.
推荐答案
使用 来自 Ant Contrib 的 propertyregex 任务.
Use the propertyregex task from Ant Contrib.
我想你想要:
<propertyregex property="propB"
input="${propA}"
regexp=" "
replace="_"
global="true" />
不幸的是,给出的例子不是很清楚,但值得一试.如果没有任何下划线,您还应该检查会发生什么 - 您可能还需要使用 defaultValue
选项.
Unfortunately the examples given aren't terribly clear, but it's worth trying that. You should also check what happens if there aren't any underscores - you may need to use the defaultValue
option as well.
这篇关于替换 Ant 属性中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!