如何在蚂蚁中逃避反斜杠 [英] 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
推荐答案
您可以使用:http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html
虽然我不确定这是否会满足您的要求.当您回显您的属性时,反斜杠是否可见?
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屋!