蚂蚁字符串函数? [英] Ant string functions?
本文介绍了蚂蚁字符串函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
蚂蚁是否有做串大/小写/ captialize / uncaptialize字符串操作的方法吗?我看着PropertyRegex但我不相信,最后两个可能这一点。是其他任何东西?
Does Ant have any way of doing string uppercase/lowercase/captialize/uncaptialize string manipulations? I looked at PropertyRegex but I don't believe the last two are possible with that. Is that anything else?
推荐答案
从这个线程,使用Ant <脚本>
任务:
From this thread, use an Ant <script>
task:
<target name="capitalize">
<property name="foo" value="This is a normal line that doesn't say much"/>
<!-- Using Javascript functions to convert the string -->
<script language="javascript"> <![CDATA[
// getting the value
sentence = project.getProperty("foo");
// convert to uppercase
lowercaseValue = sentence.toLowerCase();
uppercaseValue = sentence.toUpperCase();
// store the result in a new property
project.setProperty("allLowerCase",lowercaseValue);
project.setProperty("allUpperCase",uppercaseValue);
]]> </script>
<!-- Display the values -->
<echo>allLowerCase=${allLowerCase}</echo>
<echo>allUpperCase=${allUpperCase}</echo>
</target>
输出
D:\ant-1.8.0RC1\bin>ant capitalize
Buildfile: D:\ant-1.8.0RC1\bin\build.xml
capitalize:
[echo] allLowerCase=this is a normal line that doesn't say much
[echo] allUpperCase=THIS IS A NORMAL LINE THAT DOESN'T SAY MUCH
BUILD SUCCESSFUL
更新作为WarrenFaith的评论对脚本分离到另一个目标,并从称为目标传递特性 回调用目标的
Update for WarrenFaith's comment to separate the script into another target and pass a property from the called target back to the calling target
从蚂蚁contrib请罐使用 antcallback
Use antcallback from the ant-contrib jar
<target name="testCallback">
<antcallback target="capitalize" return="allUpperCase">
<param name="param1" value="This is a normal line that doesn't say much"/>
</antcallback>
<echo>a = ${allUpperCase}</echo>
</target>
和利用
任务使用传入参数1
从而
<target name="capitalize">
<property name="foo" value="${param1}"/>
最终输出
[echo] a = THIS IS A NORMAL LINE THAT DOESN'T SAY MUCH
这篇关于蚂蚁字符串函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文