如何逃避蚂蚁的反斜杠

时间:2011-10-05 00:44:16

标签: ant

我正在编写Ant脚本。

我有一个具有以下值的属性:     “C \:Program Files \\ test1 \\ test2”

Ant中是否有方法将其转换为:     C:Program Files \ test1 \ test2

1 个答案:

答案 0 :(得分:0)

您可以使用:http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html

虽然我不确定这是否能满足您的要求。当您回复财产时,反斜杠是否可见?

无论如何要使用上述任务,你必须安装ant-contrib并简单地写一个这样的任务:

<project name="test" default="build">
<!--Needed for antcontrib-->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>

<target name="build">

    <property name="path" value="C\:Program Files\\test1\\test2"/>
    <echo message="Path with slashes : ${path}"/>
    <propertyregex  property="removed.backslash.property"
                input="${path}"
                global="true"
                regexp="\\(\\|:)"
                replace="\1"
    />
    <echo message="Path with single slashes : ${removed.backslash.property}"/>
</target>

</project>

输出:

build:
 [echo] Path with slashes : C\:Program Files\\test1\\test2
 [echo] Path with single slashes : C:Program Files\test1\test2

此外,您可以使用任何BSF语言:

http://ant.apache.org/manual/Tasks/script.html

如果你使用的是1.6及以上的jre。