简体   繁体   English

从字符串中提取字符(Ant-Eclipse)

[英]Extract characters from a string (Ant - Eclipse)

I'm new to Ant and i need some help. 我是Ant的新手,我需要一些帮助。 I'm receiving a string through an input (dir = 4.2.1), and I want to divide it and use like two variables (dir1 = 4.2 and dir2 = 4.2.1) 我正在通过输入接收一个字符串(dir = 4.2.1),我想将其划分并像两个变量一样使用(dir1 = 4.2和dir2 = 4.2.1)

    <input message="Digite o nome do arquivo WAR que sera gerado: "
           defaultvalue="docflow"
           addproperty="nome">
    </input>

    <input message="Digite o caminho onde o WAR sera armazenado: "             
           addproperty="dir">
    </input>


   <mkdir dir="${docflow4-web-home}/${dir1}/${dir2}/deploy"/>

Here is one way. 这是一种方法。

<project default="test">

    <target name="test">

        <property name="dir" value="4.2.1"/>

        <loadresource property="dir1">
          <string value="${dir}"/>
          <filterchain>
            <tokenfilter>
              <replaceregex pattern="(.*)\.[^\.]+" replace="\1"/>
            </tokenfilter>
          </filterchain>
        </loadresource>

        <echo message="${dir1}"/>
        <echo message="${dir}"/>

    </target>

</project>

Output: 输出:

test:
     [echo] 4.2
     [echo] 4.2.1

Alternatively, you could use propertyregx from antcontrib. 另外,您也可以使用propertyregx从antcontrib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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