Perform a simple calculation in NANT program
Asked Answered
H

2

6

I need to do a simple addition in NANT program like 1 + 1 =2. I am finding it difficult as every variable is taken as string by default in NANT. I have also tried using int::parse but it did not work.

Regards

Sarathy

Helvetia answered 27/5, 2009 at 12:24 Comment(0)
H
5

Perhaps you can use convert::to-int. There's also an operator overview here.

I also found two examples that perhaps help to understand overall usage (example 1, example 2):

From example 1:

<if test=“${int::parse(UnitTestsResult) != 0}“>
  <fail message=“Atleast one unit test failed!“/>
</if>

From example 2:

<target name="repeat">
<property name="var1" value="0" overwrite="false" />
<echo message="${var1}" />
<property name="var1" value="${convert::to-int(var1) + 1)" />
<call target="repeat" if="${convert::to-int(var1) < 10}" />
</target>
Heavy answered 27/5, 2009 at 12:32 Comment(2)
Thanks a lot. It worked. However I did not use "conver::to-int" as it is deprecated but used int:parse instead. Thanks again. Regards SarathyHelvetia
You meant int::parse (the double-colon)Arawn
A
2
<property name="a" value="1"/> 
<echo message="${int::parse(a) + 2}" />

Gives:

[echo] 3

Accipiter answered 30/11, 2015 at 12:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.