I tried using RegExp within javascript within ant and had problems with
the whole forward slash character which would have been more elegant.
Instead I used some simple looping like this
<property name="inputString" value="foo/bar/baz/"/>
<property name="outputString" value=""/>
<!-- replace slash -->
<target name="jsreplace" depends="init">
<script language="javascript">
<![CDATA[
var inputString = project.getProperty('inputString');
//var outputString = inputString.replace (new RegExp(/\//),"");
var outputString = "";
echoinput= project.createTask("echo");
jsreplace.addTask(echoinput);
echoinput.setMessage("input = " + inputString);
echoinput.perform();
for (i = 0; i < inputString.length(); i++) {
if (inputString.substring(i,i+1) != "/") {
outputString += inputString.substring(i, i+1);
} else {
outputString += "_";
}
}
echooutput= project.createTask("echo");
jsreplace.addTask(echooutput);
echooutput.setMessage ("output = " + outputString);
echooutput.perform();
]]>
</script>
</target>
With this you obviously need javascript enabled in ant as well. Use
bsf.jar and rhino.jar (rename to js.jar)
> -----Original Message-----
> From: DJ Kingsolver [mailto:[EMAIL PROTECTED]
> Sent: 09 January 2008 00:58
> To: [email protected]
> Subject: String Manipulation
>
> Hi all,
>
> I need to do a simple string manipulation, but I'm finding it
> harder than I expected.
>
> Say I have a property like this:
> <property name="inputString" value="foo/bar/baz" />
>
> I'd like to set another property like this:
> <property name="outputString" value="${inputString (with
> '/' replaced with '_')}" />
>
> So, <echo message="${outputString}" /> would write "[echo]
> foo_bar_baz"
>
> What is a good way to achieve this?
>
> I've thought about writing inputString to a file and
> replacing the '/' with '_' using <replace>, then reading the
> changed value back out of the file.
> But I'd rather not have the overhead of writing to a file.
>
> Thanks for your help,
> DJ
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]