I use scriptdef to create a javascript tag to substring, for exemple:
<project>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
........
<target ...>
<substring text="asdfasdfasdf" start="2" end="10" property="subtext" />
<echo message="subtext = ${subtext}" />
</target>
</project>