.net 从文本文件中读取值的nant脚本
谁能给我发送一个示例nant.build文件,它从名为file.txt的文本文件中读取一个值 谢谢 麦迪.net 从文本文件中读取值的nant脚本,.net,.net,谁能给我发送一个示例nant.build文件,它从名为file.txt的文本文件中读取一个值 谢谢 麦迪 当然,如果愿意,您可以跳过第6、9和10行。 [编辑] 发现了一些价值 获取详细信息,请访问 [编辑二] 由于您希望获取文本文件第3行的值,请执行此操作 <?xml version="1.0"?> <project name="Read3rdLine" default="main"> <property name="myInt" value="0"
当然,如果愿意,您可以跳过第6、9和10行。
[编辑]
发现了一些价值
获取详细信息,请访问
[编辑二]
由于您希望获取文本文件第3行的值,请执行此操作
<?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>
在${LineToRead}行找到${myInt}
我发现使用正则表达式更灵活,因为它不依赖于行位于特定位置,而且更容易编码
<loadfile file="${filename}" property="assemblyInfo" />
<regex input="${assemblyInfo}" pattern="(?'assemblyVersion'AssemblyVersion[0-9.()"]+)" />
非常感谢binoj。我还有一个疑问??我对nant真的很陌生。所以我在这个file.txt文件中有一个值,从上面的代码中可以看到,现在我想将它与一个固定值进行比较,并寻找验证。如果这个值大于或小于,我想做一些检查。你能帮我吗??应该以它为例。它工作得很好!我将从数据库写入一个文件,然后使用ant将该值保存到一个变量中,以便在exec命令中使用。
<?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>
<loadfile file="${filename}" property="assemblyInfo" />
<regex input="${assemblyInfo}" pattern="(?'assemblyVersion'AssemblyVersion[0-9.()"]+)" />