蚂蚁字符串比较 [英] Ant strings comparison
本文介绍了蚂蚁字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在蚂蚁的脚本,我需要比较字典序2串。
是这样的:
I have a script in ant, and I need to compare 2 strings lexicographically. something like:
"1.2.3".compareTo("1.2.4")
我无法找到一个方法来做到这一点...任何想法?我使用的是1.8蚂蚁,蚁-的contrib。
I can't find a way to do so... Any ideas? I'm using ant 1.8, and ant-contrib.
感谢
推荐答案
有关此解决方案的工作,你需要有你的JAVA_HOME指向JRE 1.6或更高版本。
For this solution to work you will need to have your JAVA_HOME pointing to JRE 1.6 or later.
<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
这篇关于蚂蚁字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文