2013-05-09 169 views
0

我有一个文件包含以下分隔字符串的行获得每个子文件中的“|”,如何通过蚂蚁

C:\Temp\demo\AAA.dat | C:\test\input\AAA.dat 
C:\Temp\build\BBB.bat | C:\test\java\BBB.bat 
C:\Temp\test\CCC.xml | C:\Apps\ftp\CCC.xml 

我读每一行后,我希望能够提取由“分隔每个字符串|“, 即我得到第一行后, 我需要得到C:\ Temp \ demo \ AAA.dat和C:\ test \ input \ AAA.dat; 请帮助如何使用蚂蚁做到这一点?

我用下面的代码我只能得到每行:

<loadfile property="filelist" srcfile="C:\Temp\file1.txt"/> 
<target name="test" depends="chkInput" description="test"> 

    <for param = "line" list="${filelist}" delimiter="${line.separator}"> 
     <sequential> 
      <echo>@{line}</echo> 
     </sequential> 
    </for> 
</target> 

不是每个子由“|”分隔,请帮助如何获得通过分隔每个子“|”?

回答

0

一旦你有了这条线,你可以使用<propertyregex>来分隔这两块。

<for param = "line" list="${filelist}" delimiter="${line.separator}"> 
    <sequential> 
     <echo>@{line}</echo> 
     <var name="first.part" unset="true"/> 
     <var name="second.part" unset="true"/> 
     <propertyregex 
      property="first.part" 
      input="@{line}" 
      regex="^([^\s]*)" 
      select="\1"/> 
     <propertyregex 
      property="second.part" 
      input="@{line}" 
      regex="\|\s*([^\s]*).*$" 
      select="\1"/> 
    </sequential> 
</for> 

注意,你必须使用两<var/>任务未设置属性(或以其他方式,你不改变属性,或者新的任务来声明属性是本地<sequential/>实体。

+0

非常感谢大卫, – dateboyTom 2013-05-09 16:10:32