简体   繁体   中英

Compare two strings in ANT

Hy!

I have to compare two strings in ANT with <equals> task but even if the console show the correctly string, It's doesn't work for my code. This is the code :

<echo file="file.txt" append="true">AB${line.separator}</echo>
<echo file="file.txt" append="true">CD${line.separator}</echo>

<loadfile property="content" srcFile="file.txt">
    <filterchain>
      <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
       <param name="lines" value="1" />
      </filterreader>
    </filterchain>
</loadfile>
<echo>${content}</echo>

            <if>
                <equals arg1="${content}" arg2="AB" />
                  <then><echo message="OK"/></then>
                  <else><echo message="not OK"/></else>
            </if>

the result of the build is :

11:24:23      [echo] AB
11:24:23      [echo] not OK

Can you tell me how to fix this please? and thnks :)

I suspect arg2 attribute is missing the line separator. Try this:

<equals arg1="${content}" arg2="AB${line.separator}" />

Or, even better, try to clean content of all line separators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM