I have str1="A sample string"
. If the str1
contains sample
, I need to echo
something like match
and otherwise not matching
. I am not familiar with ant scripts. Please help me.
我有str1 =“一个示例字符串”。如果str1包含样本,我需要回显匹配之类的东西,否则不匹配。我不熟悉ant脚本。请帮帮我。
2 个解决方案
#1
14
If you are using newer ant, try... http://ant.apache.org/manual/Tasks/conditions.html
如果您使用较新的蚂蚁,请尝试... http://ant.apache.org/manual/Tasks/conditions.html
<condition property="legal-password">
<matches pattern="[1-9]" string="${user-input}"/>
</condition>
<fail message="Your password should at least contain one number"
unless="legal-password"/>
#2
10
If you just want to know if a substring exists in the string, you can use <contains>
task together with <if>
task from ant-contrib. If you want to scan for a pattern (a regexp) in a string, use <matches>
instead of <contains>
.
如果您只想知道字符串中是否存在子字符串,则可以将
Check for examples in this page: Ant Manual: Condition Tasks
检查此页面中的示例:Ant手册:条件任务
Also, a example:
还有一个例子:
<if>
<contains string="a sample string" substring="sample" />
<then>
<echo>match</echo>
</then>
<else>
<echo>not match</echo>
</else>
</if>
#1
14
If you are using newer ant, try... http://ant.apache.org/manual/Tasks/conditions.html
如果您使用较新的蚂蚁,请尝试... http://ant.apache.org/manual/Tasks/conditions.html
<condition property="legal-password">
<matches pattern="[1-9]" string="${user-input}"/>
</condition>
<fail message="Your password should at least contain one number"
unless="legal-password"/>
#2
10
If you just want to know if a substring exists in the string, you can use <contains>
task together with <if>
task from ant-contrib. If you want to scan for a pattern (a regexp) in a string, use <matches>
instead of <contains>
.
如果您只想知道字符串中是否存在子字符串,则可以将
Check for examples in this page: Ant Manual: Condition Tasks
检查此页面中的示例:Ant手册:条件任务
Also, a example:
还有一个例子:
<if>
<contains string="a sample string" substring="sample" />
<then>
<echo>match</echo>
</then>
<else>
<echo>not match</echo>
</else>
</if>