How Ant can get a value read from a file into a property value?

徘徊边缘 提交于 2019-11-29 12:20:58

问题


The file looks like:

a1,b1
a2,b2
...

I know the value "a2". How to get the value "b2" into a property value.

I know how to select line which contains "a2" by:

<linecontains>
  <contains value="a2"/>
</linecontains>

But I do not know how to set a property value to "b2". I am at your disposal for more other information.


回答1:


The following does the trick for me:

<loadfile srcfile="data" property="result">
     <filterchain>
           <linecontains>
                <contains value="a2"/>
           </linecontains>
           <tokenfilter>
                <replacestring from="a2," to=""/>
           </tokenfilter>
    </filterchain>
</loadfile>
<echo message="${result}"/>

As you pointed out, first the line the the 'a2' will be selected. The tokenfilter then replaces a2 and the colon with nothing. Hope that helps.



来源:https://stackoverflow.com/questions/823909/how-ant-can-get-a-value-read-from-a-file-into-a-property-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!