Le Monday 04 May 2009 17:27:15 Beth Hechanova, vous avez écrit : > Hi, > > > > I am looking for a way in Ant to parse a string as well as create a new > string that is zero-padded. Does Ant have any built-in tasks/functions > for manipulating strings? > > > > My input will be a version string in the format of x.y.z. I need to > take that input and create a string that is formatted to exactly 6 > characters, with each individual component of the original string > resulting in 2 characters in the result string (zero left padding if the > number is only one character). So if my original string is 1.2.3, my > resulting string will be 010203. > > > > I have been using NAnt lately and it has some built in functions for > doing this sort of string manipulation. Now I need to implement the > same logic in Ant scripts. I have been looking for something similar in > Ant, but I have yet to come across anything. I am using Ant v1.7.1. >
ant-contrib has propertyregex. You can use it in this case. Here is an example build file: <project name="test" basedir="." default="doit" xmlns:ac="antlib:net.sf.antcontrib"> <property name="orig" value="010203"/> <property name="theregex" value="^0([0-9])0([0-9])0([0-9])$$"/> <target name="doit"> <ac:propertyregex property="first" input="${orig}" regexp="${theregex}" select="\1" override="true"/> <ac:propertyregex property="second" input="${orig}" regexp="${theregex}" select="\2" override="true"/> <ac:propertyregex property="third" input="${orig}" regexp="${theregex}" select="\3" override="true"/> <echo>First is ${first} Second is ${second} Third is ${third}</echo> </target> </project> -- Francis Galiegue f...@one2team.com Ingénieur système Mob : +33 (0) 683 877 875 Tel : +33 (0) 178 945 552 One2team 40 avenue Raymond Poincaré 75116 Paris --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional commands, e-mail: user-h...@ant.apache.org