Java Mailing List Archive

Apache Ant Archive

» Ant Users List
» Ant Developers List
How to convert back slashes to forward slashes

How to convert back slashes to forward slashes

2007-08-09       - By Geoffrey Mitchell
Reply:     1     2     3     4     5     6  

Peter Reilly wrote:

>On 8/9/07, broken connection <brokenconnection@(protected)> wrote:
>>Hi Friends,
>>I take a directory path input from the end-user and store it in a
>>property,for example if its windows,it stores it as:
>This is not a valid property format: see
>so how do you store it?
Maybe not, but if you do <property name="log4j.location"
location="C:\tomcat\logs"/> on windows (of course), you will get exactly
what he describes.  Also, if you use an input task, like it sounds like
he is doing, this is perfectly viable.

I use the ant-contrib propertyregex, such as:

<propertyregex property="log4.location.2" input="${log4j.location}"
regexp="\\" replace="\\\\\\\\"/>

Yes, all of those backslashes are necessary in the replace.  Don't ask
me why.  I assume they are getting de-referenced twice.  It's not well
documented.  I had to figure it out the hard getting obtuse
errors and tweaking ramdomly until they went away.

See for more.

Also, it depends on what you are doing with the property whether any of
this matters or not.  Most tasks happily accept the single backslashes.

Geoffrey Mitchell
Home Decorator's Collection

©2008 - Jax Systems, LLC, U.S.A.