Re: How to make interpolation printing at fixed position?

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Thursday, October 16, 2008, 4:20:44 AM, HawkCoretech wrote:

> Hi, I have a special requirement. I need to make some interpolation printed
> in fixed position without being affected by length of previous one in the
> same row. because the output txt file will be read by another program, so it
> has to follow a strict format.

What kind of program is that? /-:

> for example, a template file:
> A=$a  B=$b
> 1234567890
>
> current $b is at the 9th-char position, but if value of $a is longer than 2
> chars, the $b starting position will not be at 10th-char.
>
> if $a=xy, $b=gh, output:
> A=xy  B=gh
>
> but if $a=wxyz $b=gh, the output is:
> A=wxyz  B=gh
>
> if I want B=$b is always printed at the fixed position(9th-char), it seems
> the only way is to make the length of $b's prceeding interpolation fixed. of
> course, this means some data in $a might be trimed.
>
> There is no such directive or built-in to do this. I think maybe I should
> write a user-defined directive to perform this function.
> Does any one has any suggestion?

Try this:
http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_right_pad

BTW, text/plain generating in general needs a specialized template
engine (I don't know of any). But as far as you don't need to much
aligning and line wrapping, gently-SGML-oriented stuff like FreeMarker
will do the job. (Actually, in FreeMarker you have some more control
over whitespace like in JSP, Velocity, etc. Still it's quite far from
ideal in that regard.)

> Thanks.

-- 
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.