• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ant + Split string and assign to a property

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic