ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: How to get sub string of a property value ?
Date Wed, 06 Feb 2002 23:10:31 GMT
--- Barry Jia <bjia@brightspark.com> wrote:
> for example, I define a property file.name, value is xxxx.java, how
> could I to get the sub string xxxx from that value in ant scripts?

If you've got 'basename' on all the machines you run your build on:
  <target name="runBasename">
    <exec executable="basename" outputproperty="basename">
      <arg line="${file.name} .java"/>
    </exec>
    <echo message="basename = ${basename}"/>
  </target>

Otherwise, you could use the <script> task:
  <target name="getBasename" depends="genBasename">
    <echo message="basename = ${basename}"/>
  </target>
  <target name="genBasename">
    <script language="javascript"> <![CDATA[
      importClass(java.io.File);
      file = new File(projname.getProperty("file.name"));
      basename = file.getName();
      pos = basename.indexOf('.');
      basename = basename.substring(0, pos);
      projname.setProperty("basename", basename);
      ]]>
    </script>
  </target>

Or you could write a task to do it.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message