velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: Is there a way for me to change the case of the output value?
Date Wed, 11 Jun 2003 09:59:17 GMT
Velocity uses Java and "reflection" backstage. So if your
context object is a java.lang.String, you can do:

#set ($Name = "Ben")

#macro( PascalCase $foo )
#**##set( $str = "$foo" )
#**#$str.substring(0,0).toUpperCase()$str.substring(1).toLowerCase()
## consider adding #if(#str.length > 1) and > 2 to avoid OutOfBoundsException...
#end

The name (in lowercase) is $Name.toLowerCase()
The name (in uppercase) is $Name.toUpperCase()
The name (in Pascal case) is #PascalCase($Name)
The name (in Camal case) is ...


Otherwise use a context tool (e.g. in your Java
source add a
   context.put("CaseTool", new CaseTool() );
   ...
   public class CaseTool
   {
      public String pascalCase(String name)
      {
         return ... \\ do the right thing here
      }
   }

I do remember seing such a tool over at the Turbine
subprojects...

Edward Lim wrote:
> Hi,
> 
> As per the subject line, I am wondering if there is a way to change the case of the ouput
value, eg.
> 
> #set ($Name = "Ben")
> 
> The name (in lowercase) is $name.
> The name (in uppercase) is $NAME
> The name (in Pascal case) is $Name
> The name (in Camal case) is $aNme
> 
> output:
> The name (in lowercase) is ben.
> The name (in uppercase) is BEN
> The name (in Pascal case) is Ben
> The name (in Camal case) is bEn
> 
> cheers,
> &   Edward Lim
>        Senior IT Specialist
> H   IT Project Delivery Department
>    Bank of Western Australia
>        Level 6, 148 Adelaide Terrace
>        East Perth, WA 6004
> (   (08) 9449 8917
> ý    URL: http://www.bankwest.com.au
> *   edward_lim@bankwest.com.au
> 
> 
> 
> _______________________________________________________________________________
> Unencrypted electronic mail is not secure and may not be authentic.
> If you have any doubts as to the contents please telephone to confirm.
> 
> This electronic transmission is intended only for those to whom it is
> addressed. It may contain information that is confidential, privileged
> or exempt from disclosure by law.  Any claim to privilege is not waived
> or lost by reason of mistaken transmission of this information.
> If you are not the intended recipient you must not distribute or copy this
> transmission and should please notify the sender.  Your costs for doing
> this will be reimbursed by the sender.
> _______________________________________________________________________________
> 
> 

-- 
:) Christoph Reck


---------------------------------------------------------------------
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