3 回答

TA贡献1836条经验 获得超3个赞
使用Ant Contrib的propertyregex任务。
我想你要:
<propertyregex property="propB"
input="${propA}"
regexp=" "
replace="_"
global="true" />
不幸的是,给出的例子并不清楚,但是值得尝试。您还应该检查如果没有任何下划线,会发生什么情况-您可能还需要使用该defaultValue选项。

TA贡献1825条经验 获得超6个赞
如果您想要一个仅使用Ant内置组件的解决方案,请考虑以下事项:
<target name="replace-spaces">
<property name="propA" value="This is a value" />
<echo message="${propA}" file="some.tmp.file" />
<loadfile property="propB" srcFile="some.tmp.file">
<filterchain>
<tokenfilter>
<replaceregex pattern=" " replace="_" flags="g"/>
</tokenfilter>
</filterchain>
</loadfile>
<echo message="$${propB} = "${propB}"" />
</target>
输出是 ${propB} = "This_is_a_value"
- 3 回答
- 0 关注
- 524 浏览
添加回答
举报