替换 Ant 属性中的字符 [英] Replacing characters in Ant property

查看:27
本文介绍了替换 Ant 属性中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以获取一个属性的值,然后将其复制到另一个替换了某些字符的属性中?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆