Replacing characters in Ant property

ant, string

Solution

Use the propertyregex task from Ant Contrib.

I think you want:

<propertyregex property="propB"
               input="${propA}"
               regexp=" "
               replace="_"
               global="true" />

Unfortunately the examples given aren't terribly clear, but it's worth trying that. You should also check what happens if there aren't any underscores - you may need to use the `defaultValue` option as well.

Problem

Is there a simple way of taking the value of a property and then copy it to another property with certain characters replaced? Say `propA=This is a value`. I want to replace all the spaces in it into underscores, resulting in `propB=This_is_a_value`.

Original source