views:

2432

answers:

2

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.

+5  A: 

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.

Jon Skeet
Thanks! That worked. And here I was trying to come up with an overly complicated regexp for the replacement.... lol
aberrant80
+1  A: 

Thanks. I found this answer useful too, but careful those who are copying and pasting this, as those should be {} brackets around the propA: input="${propA}"

Paul.

Paul