蚂蚁字符串比较 [英] Ant strings comparison

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

问题描述

我在 ant 中有一个脚本,我需要按字典顺序比较 2 个字符串.类似:

I have a script in ant, and I need to compare 2 strings lexicographically. something like:

 "1.2.3".compareTo("1.2.4")

我找不到这样做的方法...有什么想法吗?我使用的是 ant 1.8 和 ant-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屋!

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