Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Ant + Split string and assign to a property  RSS feed

 
Easwara Murthy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a collection of strings separated by semicolon say, txt1;txt2;txt3;txt4;txt5 (which is available in a property)

I have to split this group of strings based on semicolon. While reading each string (say, first i get the string txt1), i need to assign the string to a variable (and then invoke a target). How can this be achieved using ant.

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ant-contrib library has a for loop that you can use to call a target with the split values. It assigns each one to a temporary variable when calling the new target.
 
Donald Skidmore
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<target Name="main">
<property semicolon="txt1;txt2;txt3;txt4;txt"/>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
def str=properties.semicolonstring;
def eachstr= str.split(";");
properties.str1 = eachstr[0];
properties.str2 = eachstr[1];
</groovy>
<antcall target="results"/>
</target>
<target name="results">
<echo>str1=${str1}</echo>
<echo>str2=${str2}</echo>
</target>

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!