如何比较字符串列表?


 <target name="build">
 <for list="${platform}" param="platform" trim="true">
 <sequential>
 <if>
 <equals arg1="${platform}" arg2="${project.SuppoortedPlatforms}" />
 <then>
 <antcall target="package.${platform}" />
 </then>
 </if>
 </sequential>
 </for>
 </target>

我在运行时获得平台值(例如:windows,ios)和项目。supportedplatforms在build下声明。属性(例如:android, ios)。如何比较字符串列表?有人能帮我解决这个问题吗?

谢谢,sandhiya

您正在遍历一个以逗号分隔的平台列表,并且对于每个平台,您正在检查它是否包含在project.SuppoortedPlatforms中支持的平台列表中。它应该是这样的:

<for list="${platform}" param="platformParam" trim="true">
    <sequential>
    <if>
       <contains string="${project.SuppoortedPlatforms}" substring="@{platformParam}" />
        <then>
          <antcall target="package.@{platformParam}" />
        </then>
      </if>
       </sequential>
     </for>

循环中的参数应该用@而不是$来访问。此外,为了可读性,最好重命名参数(platformParam而不是platform)。

  Instead of using contains task, i myself tried with the nested for loop, its cool working fine. 

  <for list="${platforms}" param="platformparam" trim="true">
 <sequential>
    <for list="${project.SupportedPlatforms}" param="supplatformparam" trim="true">
    <sequential>
        <if>
        <equals arg1="@{platformparam}" arg2="@{supplatformparam}" />
        <then>
            <antcall target="package.@{platformParam}" />
        </then>
        </if>
    </sequential>
    </for>
</sequential>
</for>

相关内容

  • 没有找到相关文章

最新更新