3 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊
使用Ant Contrib的propertyregex任務(wù)。
我想你要:
<propertyregex property="propB"
input="${propA}"
regexp=" "
replace="_"
global="true" />
不幸的是,給出的例子并不清楚,但是值得嘗試。您還應(yīng)該檢查如果沒(méi)有任何下劃線,會(huì)發(fā)生什么情況-您可能還需要使用該defaultValue選項(xiàng)。

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果您想要一個(gè)僅使用Ant內(nèi)置組件的解決方案,請(qǐng)考慮以下事項(xiàng):
<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 關(guān)注
- 548 瀏覽
添加回答
舉報(bào)