簡體   English   中英

比較ANT中的兩個字符串

[英]Compare two strings in ANT

我必須將ANT中的兩個字符串與<equals>任務進行比較,但是即使控制台顯示正確的字符串,它也不適用於我的代碼。 這是代碼:

<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>

構建的結果是:

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

你能告訴我如何解決這個問題嗎? 和thnks :)

我懷疑arg2屬性缺少行分隔符。 嘗試這個:

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

或者,甚至更好地,嘗試清理所有行分隔符的content

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM