How to get substring of a string in ANT property -


i have requirement substring out of string in property.

example string:

1=tibunit-1.4.2.projlib\= 

i want extract part before .projlib\= , after first =.

the result should be:

tibunit-1.4.2 

any ideas?

use script task builtin javascript engine (jdk >= 1.6.0_06) , :

if need substring 'tibunit-1.4.2.projlib\' :

<project>   <property name="foo" value="1=tibunit-1.4.2.projlib\="/>   <script language="javascript">   // simple echo   println(project.getproperty('foo').split('=')[1]);   // create property later use   project.setproperty('foobar', project.getproperty('foo').split('=')[1]);  </script>   <echo>$${foobar} => ${foobar}</echo>  </project> 

output :

[script] tibunit-1.4.2.projlib\ [echo] ${foobar} => tibunit-1.4.2.projlib\ 

if need substring 'tibunit-1.4.2' :

<project>   <property name="foo" value="1=tibunit-1.4.2.projlib\="/>   <script language="javascript">   s = project.getproperty('foo').split('=')[1];   // simple echo   println(s.substring(0, s.lastindexof(".")));   // create property later use   project.setproperty('foobar', s.substring(0, s.lastindexof(".")));  </script>   <echo>$${foobar} => ${foobar}</echo>  </project> 

output:

[script] tibunit-1.4.2 [echo] ${foobar} => tibunit-1.4.2 

for reuse put stuff macrodef.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -