velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr. <ge...@adeptra.com>
Subject Re: String to Int
Date Sat, 07 Dec 2002 02:22:41 GMT

On Friday, December 6, 2002, at 01:08 PM, Johnny Dynn wrote:

> Newbie question....
>
> Say I have a string in velocity...
>
> #set($num_loop = "5")
>
> How can I convert that so I can, for example, use it
> in a foreach loop?
>
> eg.
>
> #foreach( $i in [1..$num_loop] )
>   $i
> #end
>
> I know I can just set the loop_count to 1 instead of
> "1" but I was just curious if there some way.

Velocity doesn't provide (by itself) any tools or utilities in the 
context for you to use.  The intent is that you can add your own to 
take care of the things that you need.  One strategy is to always 
provide a common toolbox for people to use.

That said, you can be devious.  You can take advantage of Velocity's 
introspection via something like :

#set($int = 1)
#set($val = $int.parseInt("4"))

#foreach($val in [0..$val])
$val
#end

because $int is an Integer, so you can call any method of Integer using 
this...

>
> Thanks,
>
>
> jd
>
> ______________________________________________________________________
> Post your free ad now! http://personals.yahoo.ca
>
> --
> To unsubscribe, e-mail:   
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:velocity-user-help@jakarta.apache.org>
>
>
-- 
Geir Magnusson Jr                                   203-355-2219(w)
Adeptra, Inc.                                       203-247-1713(m)
geirm@adeptra.com


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


Mime
View raw message