Hi,

I used a macro for zero-padding, which can easily be modified to space-padding:
#macro( fourdigits $number )#*
  *##* #local( $id $len ) *##*        -- optional directive, avoids polluting 
context
  *##set( $id = "$number" )#*         -- access the macro paramter, ensure its 
a String
  *##set( $id = "0000$id.trim()" )#*  -- prepend the padding, clipping 
whitespace artefacts
  *##set( $len = $id.length() - 4 )#* -- compute the offset for the rest length
  *#$id.substring($len)#*             -- emit the resulting padded string
  *##* #end *###                      -- close the optional #local directive
#macro

See original thread in:
  http://www.mail-archive.com/[email protected]/msg14419.html

Also see other useful macros in the wiki:
  http://wiki.apache.org/jakarta-velocity/VelocityGenericMacros

But beware of the velocity whitepace handling...
To avoid extra whitepaces either place everything on the left
margin (no indentation) or do asin above macro example with
block comments and eol-comments.

Cheers,
:) Christoph Reck


Janos Mucsi wrote:
Hi
I need to have fixed length fields. Is there a way in
Velocity to format the output of a variable so it is
padded with whitespaces (in the output) to a specific
length.
Thanks.
Janos

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to