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.
If you are using newer ant, try... 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"/>
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
Also, a example:
<if>
<contains string="a sample string" substring="sample" />
<then>
<echo>match</echo>
</then>
<else>
<echo>not match</echo>
</else>
</if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With