如何在Ant脚本中增加字符数据类型?
例如:如何在Ant脚本中增加字符数据类型?,ant,Ant,例如: <project name="num" default="jav"> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <!-- IF and Conditional task inbuild taskdef --> <target name="jav"> <property file="proper.properties"/>
<project name="num" default="jav">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<!-- IF and Conditional task inbuild taskdef -->
<target name="jav">
<property file="proper.properties"/>
<math result="index" operand1="${index}"
operation="+" operand2="1" datatype="int"/>
<echo message="index=${index}"/>
<echo file="proper.properties" message="index=${index}"/>
</target>
</project>
在property.properties
中,我有一个index=1A
。我可以增加整数部分,但不能增加字符部分
我有一个变量index=1A
。我想在每个构建过程之后增加这个数字
假设我已经完成了第一个构建,那么它应该是index=2B
。也就是说,我想在Ant脚本中增加整数和字符值(1A
,2B
,3C
,…)
这在Ant中可能吗?您可以使用以下内容:
<project name="test" default="init">
<property name="init.value" value="1A"/>
<scriptdef name="increase.label" language="javascript">
<attribute name="value" />
<attribute name="property" />
<![CDATA[
var initVal = attributes.get("value");
var finalVal = String.fromCharCode(initVal.charAt(0) + 1);
for(i = 1; i < initVal.length(); i++)
{
finalVal = finalVal.concat(String.fromCharCode(initVal.charAt(i) + 1));
}
project.setProperty(attributes.get("property"), finalVal);
]]>
</scriptdef>
<target name="init">
<increase.label value="1A" property="result"/>
<echo message="Result is : ${result}"/>
</target>
</project>
编辑:
现在,您希望增加数字,而不是字符。使用parseInt(字符串,基数)
不过我不知道你想用字母做什么。在这里,您必须添加一个新字母。使用内联“脚本”任务。我个人使用Beanshell做一些字符处理,比如用某些部分拆分字符串。。。。检查此项:当我取
init.value=9I
时,它会将其递增为:J
,但我希望它是10J
如何才能做好,字母也会发生这种情况。当你去Z的时候会发生什么?增量是以字符表示的,因此ASCII中的9之后会出现:这就是您得到的结果。在你的问题中,你谈论的是角色数据。现在你谈论的是数字。您可以通过解析数字或添加逻辑来实现这一点。我会选择第一个选项。这里我的要求是,如果我选择1A,那么它应该是增量,比如1A,2B,3C…10J,11K…意味着两个数据都应该是增量,意味着整数和字符…@野餐4u你没有回答另一个问题。当你到达Z?4U时会发生什么?期望的输出是什么?
init:
[echo] Result is : 2B