4
A
回答
12
<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd"
name="Company.Portal.Domain" default="GetFile">
<call target="GetFile" />
<target name="GetFile">
<echo message="Retrieving file contents"/>
<property name="file.contents" value="0" />
<loadfile file="file.txt" property="file.contents" />
<property name="file.contents" value="${string::trim(file.contents)}" />
<echo message="contents of file is ${file.contents}"/>
</target>
</project>
当然,如果你愿意,你可以跳过线6,9和10。 [编辑]
<if test="${file.contents=='someValue'}">
<echo>Some value found</echo>
</if>
[EDIT2]
获取全部细节既然你想要得到的文本文件中的第三行的值,那么做到这一点
<?xml version="1.0"?>
<project name="Read3rdLine" default="main">
<property name="myInt" value="0"/>
<property name="x" value="0"/>
<property name="LineToRead" value="3"/>
<target name="main" description="compiles the source code">
<property name="i" value="0"/>
<foreach item="Line" in="file.txt" property="x" trim="Both">
<property name="i" value="${int::parse(i) + 1}"/>
<if test="${i==LineToRead}">
<property name="myInt" value="${x}"/>
</if>
</foreach>
<echo>found ${myInt} at line ${LineToRead}</echo>
</target>
</project>
0
我发现使用正则表达式更加灵活,因为它不依赖于一行来处于特定的位置并且更易于编码。
<loadfile file="${filename}" property="assemblyInfo" />
<regex input="${assemblyInfo}" pattern="(?'assemblyVersion'AssemblyVersion[0-9.()"]+)" />
的语法是有点奇怪,但2号线的结果是填充属性调用assemblyVersion
与正则表达式的分组模式相匹配的字符串:一切
相关问题
- 1. 从文件 - shell脚本中读取值
- 2. 编写一个脚本以读取许多类似文件名的.csv文件
- 3. 修改脚本以从文本文件中读取
- 4. 如何在文件夹中编写和读取文本文件?
- 5. bash脚本读取文件
- 6. Powershell脚本以较小的批次读取文本文件。
- 7. 使用java编写和读取文本文件中的数字
- 8. Python - 从正在Windows中编写的文本文件读取
- 9. 修改bash脚本以在读取文件时排除文本
- 10. 写入文本文件和读取文本文件时的垃圾值
- 11. 从perl脚本输出文件以供bash脚本读取
- 12. 从文本中读取数字值已经在Android中编写的文件
- 13. 读取文本文件的值并将值写入QDoubleSpinBox
- 14. RPM +在spec文件中编写脚本
- 15. Java从文本文件中读取值
- 16. C从文本文件中读取值
- 17. 从文本文件中读取值?
- 18. 在C编程中读取/写入文本文件
- 19. Flash动作脚本可以读写本地文件系统吗?
- 20. 写入/读取文本文件(C#)
- 21. 读取和写入文本文件
- 22. 读取/写入文本文件
- 23. Java - 读取和写入文本文件
- 24. 需要从文本文件中读取的VB脚本
- 25. shell脚本:从文件中读取
- 26. 从新贵脚本中读取文件
- 27. Python脚本从csv文件中读取
- 28. 从脚本中读取TDM(Diadem)文件
- 29. 在nsis脚本中读取.inf文件
- 30. 在java脚本中读取文本
多谢内(?) binoj.Just得到了另一个疑问??我对nant真的很陌生。因此,我在这个file.txt中有一个值,它是从上面的代码中看到的,现在我想将它与一个固定值进行比较并查找验证。如果这个值大或小,我想做一些checks.CanüPLZ帮助? – Maddy 2009-04-10 12:45:36