2009-04-10 3 views

답변

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을 건너 뛸 수 있습니다 물론. [편집] 당신이 다음이

<?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> 
을 텍스트 파일의 셋째 줄의 값을 얻으려면 때문에

<if test="${file.contents=='someValue'}"> 
    <echo>Some value found</echo> 
</if> 

this link

[EDIT2]

에서 자세한 내용을 가져 오기

+0

덕분에 많은 내부 (?) binoj.Just는 또 다른 의문을 가지고 있습니다. "나는 정말로 nant를 처음 사용합니다. 그래서 위의 ur 코드에서 볼 수 있듯이이 file.txt에 값이 있습니다. 이제 고정 값과 비교하고 유효성 검사를 원합니다. 이 값이 크거나 작 으면 몇 가지 확인을 해보십시오. 도움이 필요하십니까 ?? – Maddy

+0

이어야합니다 –

+0

예를 들어 주셔서 감사합니다. 그것은 위대한 작품! 데이터베이스에서 파일에 쓰고 ant를 사용하여이 값을 exec 명령에 사용할 변수에 저장합니다. – PHPGuru

0

정규 표현식을 사용하면 특정 위치에 있어야 라인에 의존하지 않고 코딩하기가 더 쉽기 때문에보다 유연하다는 것을 알게되었습니다.

<loadfile file="${filename}" property="assemblyInfo" /> 
<regex input="${assemblyInfo}" pattern="(?'assemblyVersion'AssemblyVersion[0-9.()&quot;]+)" /> 

구문은 조금 이상한하지만, 2 라인의 결과는 정규식 그룹화 패턴과 일치하는 문자열 속성 호출 assemblyVersion을 채울 것입니다 : 모든

관련 문제