如何在 Ant 中提取子字符串 [英] How to pull out a substring in Ant
本文介绍了如何在 Ant 中提取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从 Ant 属性中提取子字符串并将该子字符串放入它自己的属性中?
Is there a way to pull a substring from an Ant property and place that substring into it's own property?
推荐答案
我使用 scriptdef 创建了一个 javascript 标记来子字符串,例如:
I use scriptdef to create a javascript tag to substring, for exemple:
<project>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
........
<target ...>
<substring text="asdfasdfasdf" start="2" end="10" property="subtext" />
<echo message="subtext = ${subtext}" />
</target>
</project>
这篇关于如何在 Ant 中提取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文