蚂蚁字符串函数? [英] Ant string functions?

查看:26
本文介绍了蚂蚁字符串函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant 有没有办法对字符串进行大写/小写/大写/取消大写操作?我查看了 PropertyRegex,但我不相信最后两个是可能的.还有别的吗?

解决方案

从此线程,使用Ant <!-- 显示值--><echo>allLowerCase=${allLowerCase}</echo><echo>allUpperCase=${allUpperCase}</echo></目标>

输出

D:\ant-1.8.0RC1\bin>ant 大写构建文件:D:\ant-1.8.0RC1\bin\build.xml大写:[echo] allLowerCase=这是一条正常的线路,不多说[echo] allUpperCase=这是一条没有多说的普通行建造成功

更新 WarrenFaith 的评论,将脚本分离到另一个目标中,并将一个属性从被调用的目标 传回调用目标

使用来自 ant-contrib jar 的 antcallback

<antcallback target="capitalize" return="allUpperCase"><param name="param1" value="这是一条普通的线路,不多说"/></antcallback><echo>a = ${allUpperCase}</echo></目标>

and capitalise 任务使用传入的 param1 因此

 <property name="foo" value="${param1}"/>

最终输出

 [echo] a = 这是一条没多说的普通线路

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?

解决方案

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>

Output

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

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

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>

and capitalise task uses the passed in param1 thus

 <target name="capitalize">

        <property name="foo" value="${param1}"/>

Final output

   [echo] a = THIS IS A NORMAL LINE THAT DOESN'T SAY MUCH

这篇关于蚂蚁字符串函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆