问题描述
我有一只蚂蚁文件,因为这个ini文件被更新而更新Ant文件中的数据,并在顶部有评论如下:
I have an ant file which updates the data in ant file due this ini file gets updated and at the top it has a comment as follows
#Thu, 07 Jul 2011 06:54:54 -0500
我不希望这条评论,因为我通过PHP中使用parse_ini访问此文件。由于此评论我得到一个失败
I don't want this comment as i am accessing this file by php using parse_ini. Due to this comment i get an failure
Comments starting with '#' are deprecated in build.ini on line 1
那么,有没有办法让我不会在ini文件的注释。
so is there any way so that i will not get the comment in ini file.
感谢。
编辑:
<propertyfile file="build.ini">
<entry key="build-number" type="int" operation="+" value="1" />
</propertyfile>
+1这将更新我的ini文件集结号
this updates my ini file build-number by +1
推荐答案
马丁的评论点你的方式使用replaceregexp删除评论。 (我正要告诉你有类似的想法,但使用移动filterchain和striplinecomments,但replaceregexp更加紧凑。)
Martin's comment points you to a way to remove comments using replaceregexp. (I was about to show you a similar idea but using move, filterchain and striplinecomments. But the replaceregexp is more compact.)
其他的建议,我是因为你正在编辑INI文件,也许你应该使用专门针对该任务,而不是使用的任务。有一个 TAKS在蚂蚁的contrib可能做的工作。
The other suggestion I have is that since you are editing ini files, maybe you should use a task dedicated to that, rather than using the PropertyFile task. There is an IniFile taks in ant-contrib might do the job.
如果该replaceregexp不为你工作,因为你的文件中有其他#的意见和您只想要删除顶线,那就试试这个:
If the replaceregexp doesn't work for you because your file has other # comments in it and you only want to remove that top line, then try this:
<target name="test">
<propertyfile file="test.properties">
<entry key="key" value="value"/>
</propertyfile>
<move file="test.properties" tofile="test.properties.tmp">
<filterchain>
<headfilter lines="-1" skip="1"/>
</filterchain>
</move>
<move file="test.properties.tmp" tofile="test.properties"/>
</target>
输出:
$ cat test.properties
one=1
# existing comment
$ ant
Buildfile: C:\tmp\ant\build.xml
test:
[propertyfile] Updating property file: C:\tmp\ant\test.properties
[move] Moving 1 file to C:\tmp\ant
[move] Moving 1 file to C:\tmp\ant
BUILD SUCCESSFUL
Total time: 0 seconds
$ cat test.properties
one=1
# existing comment
key=value
这篇关于更新ini文件中删除时,由蚂蚁writen ini文件评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!