[Ant][StartWithAnt] 第五章 条件判断Contidion 3.字符串匹配

来源:互联网 发布:网络运营部职责 编辑:程序博客网 时间:2024/04/28 17:24

点击此处下载StartWithAnt完整的pdf文档与代码:http://download.csdn.net/detail/sodino/6603769


可以使用equals任务来判断两个给定的字符串内容是否相同。equals任务重要的属性说明如下:

arg1/arg2:指定两个用来对比的字符串,这两个参数必须有被赋值。

casesensitive:设定在匹配过程中是否区分大小写,默认值为true区分大小写。

trim:在匹配过程中是否去除空格再比较。默认为false

可以使用contains任务来判断能否在指定的字符串中搜索出另一个字符串。contains任务只有三个属性:

string:指定被搜索的字符串。

substring:指定搜索的字符串。

casesensitive:是否区分大小写。默认为true区分大小写。

下面给出示例代码:

<property name="Apple" value="Apple"/><property name="string.a" value="I'm a red ${Apple}"/><property name="string.b" value="I'm a flying Bee"/><condition property="a.equals.b" value="true" else="false"><equals arg1="${string.a}" arg2="${string.b}"/></condition><condition property="isContains" value="true" else="false"><contains string="${string.a}" substring="${Apple}"/></condition><target name="Condition"><echo message="string.a equals string.b: ${a.equals.b}"/><echo message="string.a contains Apple: ${isContains}"/></target>

代码5.6 字符串匹配

5.2 字符串匹配结果

原创粉丝点击