length-safe substring ?

Grégory Joseph <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hi,

When trying to display the first N characters of a string, not knowing the size of said string, in my template, I'm doing this:
[#assign foo='a fairly short string']

${foo?right_pad(50)?substring(0, 50)?trim}

This seems rather cumbersome, wouldn't you agree? Another option would be to use if blocks; not much more readable.

So what I'm asking:
- is there a simpler/shorter way of doing the same ?
- if not, would a new built-in make sense ? Or changing the behavior of the existing one to be more lenient than its java.lang.String equivalent ?

Cheers,

-g



------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
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.