Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ant + Split string and assign to a property

 
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
Marshal
Posts: 34839
369
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>

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic