[stringtemplate-interest] Truncate string?

Zenaan Harkness zen at freedbms.net
Wed May 20 07:02:18 PDT 2009


I have a rather complex and featureful formatter class, which does
various custom things I need, some of which are generally useful.

As I don't have the time just now to tidy it all up for public
consumption, here's the simple method I use to do string truncation:

public class MyRenderer implements AttributeRenderer {

public String toString (Object o, String format) {
   // truncate to max length
   final int max = Integer.decode(format).intValue();
   return ostring.substring(0, Math.min(max,ostring.length()));
}

}


In your st group do

group.registerRenderer(String.class, new MyRenderer());

hth
zen

-- 
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list