velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sitaram Krishnamurthy <skris...@tibco.com>
Subject RE: Issue with #set/replaceAll
Date Mon, 06 Sep 2004 17:23:25 GMT
Thanks Shinobu. Answer is good if the $Map/test is in the velocity template.
But how would you deal with the same if I had something like
#set ($def = $attr.getMapper()) and $attr.getMapper() returned $Map/test

How do I escape $ in such cases?

Thanks
Sitaram


> -----Original Message-----
> From: Shinobu Kawai [mailto:shinobu.kawai@gmail.com]
> Sent: Monday, September 06, 2004 9:36 PM
> To: skrishna@tibco.com
> Subject: Re: Issue with #set/replaceAll
> 
> Hi Sitaram,
> 
> > I would want to replace all occurrences of CONTAINER/test with $Map/test
> > Finally when I print $test it should look
> > "My String is $Map/test"
> 
> > > > #set ($try = "My String is CONTAINER/test")
> > > > #set ($abc = "CONTAINER/test")
> > > > #set ($def = '$Map/test)
> > > > #set ($test = $try.replaceAll($abc,$def)
> > > > Test is $test
> What you have here, is a regex problem, not a Velocity problem.  Since
> "$" is a special character for replacements, you have to escape them to
> use it as is.
> 
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html#appen
> dReplacement(java.lang.StringBuffer,
> java.lang.String)
> 
> Try the following:
>    #set ($def = '\$Map/test')
> 
> Best regards,
> -- Shinobu Kawai
> 
> --
> Shinobu Kawai(shinobu.kawai@gmail.com)


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message