如何在蚂蚁中逃脱反斜线 [英] how to escape backslash in ant
问题描述
我正在编写Ant脚本.
I am writing Ant scripts.
我有一个属性,其值是: "C \:Program Files \\ test1 \\ test2"
I have a property which has the value: "C\:Program Files\\test1\\test2"
Ant中是否有一种方法可以将其转换为: C:\ Program Files \ test1 \ test2
Is there a method in Ant to convert it to: C:Program Files\test1\test2
推荐答案
您可以使用:尽管我不确定这是否能满足您的要求.回显属性时,反斜线是否可见?
although I am not sure if this will do what you are asking for. Are the backslashes visible when you echo your property?
无论如何要使用上述任务,您都必须安装ant-contrib并简单地编写一个像这样的任务:
In any case to use the above task you will have to have ant-contrib installed and simply write a task like this :
<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语言:
In addition you could use any of the BSF languages :
http://ant.apache.org/manual/Tasks/script.html
前提是您使用的是jre 1.6及更高版本.
provided you are using jre 1.6 and above.
这篇关于如何在蚂蚁中逃脱反斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!