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