如何通过Ant获取文件中的每个子字符串
我有一个文件,其中包含以下由“|”分隔的字符串行 在我读了每一行之后,我希望提取每个由“|”分隔的字符串, 也就是说,在我拿到第一条线之后, 我需要同时获得C:\Temp\demo\AAA.dat和C:\test\input\AAA.dat; 请帮助如何使用蚂蚁做它 我使用以下代码,我只能得到每一行:如何通过Ant获取文件中的每个子字符串,ant,Ant,我有一个文件,其中包含以下由“|”分隔的字符串行 在我读了每一行之后,我希望提取每个由“|”分隔的字符串, 也就是说,在我拿到第一条线之后, 我需要同时获得C:\Temp\demo\AAA.dat和C:\test\input\AAA.dat; 请帮助如何使用蚂蚁做它 我使用以下代码,我只能得到每一行: <loadfile property="filelist" srcfile="C:\Temp\file1.txt"/> <target name="test" depends="
<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>
@{line}
不是每个子字符串都用“|”分隔,请帮助如何将每个子字符串用“|”分隔?一旦您有了行,您可以使用
来分隔这两部分
<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>
@{line}
注意:您必须使用
任务来取消设置属性(否则,您不会更改属性),或者使用新任务来声明该属性是
实体的本地属性
<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>