velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Streithorst, Kip" <kstre...@ball.com>
Subject RE: Am I missing something simple? calling java.lang.String.repla ce(c har, char)
Date Wed, 03 Apr 2002 17:32:22 GMT
The workaround will suffice. 

Thanks, 
Kip 

> -----Original Message----- 
> From: Geir Magnusson Jr. [ mailto:geirm@optonline.net
<mailto:geirm@optonline.net> ] 
> Sent: Wednesday, April 03, 2002 10:10 AM 
> To: velocity-user@jakarta.apache.org 
> Subject: Re: Am I missing something simple? calling 
> java.lang.String.replace(c har, char) 
> 
> 
> On 4/3/02 9:57 AM, "Streithorst, Kip" <kstreith@ball.com> wrote: 
> 
> > I am trying to call java.lang.String.replace(char oldChar, 
> char newChar) 
> > 
> > in my velocity template using 
> > 
> > $thestring.replace('\\', '/') 
> > 
> > But this doesn't seem to work. 
> > 
> 
> Beautiful problem :) 
> 
> There are a whole bunch of things wrong here.  First, 
> '<stuff>' is a string, 
> not a char.  The diff between "" and '' is that '' isn't interpolated.

> 
> So 
> #set($foo = 'hello') 
> #set($bar = "$foo") 
> #set($woogie = '$foo') 
> $bar 
> $woogie 
> 
> Outputs 
> 
> Hello 
> $foo 
> 
> We have no natural way to specify a char in Velocity.  That's 
> why the method 
> isn't getting called. 
> 
> So you can resort to a horror show like : 
> 
> #set($foo = "hello?") 
> #set($thingy = "?!") 
> #set($a = $thingy.charAt(0)) 
> #set($b = $thingy.charAt(1)) 
> $foo 
> $foo.replace($a, $b) 
> 
> And that works. 
> 
> I have no immediate ideas on what to do about the fact we 
> have no way of 
> representing a char... 
> 
> -- 
> Geir Magnusson Jr.                                     
> geirm@optonline.net 
> System and Software Consulting 
> Somebody has to do something, and it's just incredibly 
> pathetic that it has 
> to be us.  - Jerry Garcia 
> 
> 
> -- 
> To unsubscribe, e-mail:   
> < mailto:velocity-user-unsubscribe@jakarta.apache.org
<mailto:velocity-user-unsubscribe@jakarta.apache.org> > 
> For additional commands, e-mail: 
> < mailto:velocity-user-help@jakarta.apache.org
<mailto:velocity-user-help@jakarta.apache.org> > 
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message