我在 ant 中有一个脚本,我需要按字典顺序比较 2 个字符串。
就像是:
"1.2.3".compareTo("1.2.4")
我找不到办法这样做...有什么想法吗?我正在使用 ant 1.8 和 ant-contrib。
Thanks
为了使此解决方案发挥作用,您需要将 JAVA_HOME 指向 JRE 1.6 或更高版本。
<project name="test" default="test">
<scriptdef name="compare" language="javascript">
<attribute name="lhs" />
<attribute name="rhs" />
<attribute name="property" />
<![CDATA[
var lhs = attributes.get("lhs");
var rhs = attributes.get("rhs");
project.setProperty(attributes.get("property"), lhs > rhs);
]]>
</scriptdef>
<target name="test">
<compare lhs="1.2.3" rhs="1.2.4" property="result"/>
<echo message="Result is : ${result}"/>
</target>
</project>
输出 :
test:
[echo] Result is : false
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)