Re: [FMPP] how to get a substring out of a variable or file name?
Brought to you by:
ddekany
|
From: Daniel D. <dd...@fr...> - 2003-07-19 15:07:43
|
Saturday, July 19, 2003, 4:49:26 PM, Ralf Hauser wrote: > Daniel, > > From a filename_en.jsp, I would like to extract the two language indicating > characters. > http://www.freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_stri > ngop_sub doesn't really help if I probably have to count from the right or > do some regular expression pattern matching. For regular expression operations, see: ref_builtins_string.html > I thought > ${pp.sourceFile[-6..-5]} > might be it, but I got > << [fmpp] Caused by: java.lang.StringIndexOutOfBoundsException: String > index out of range: -6> > > Any thoughts, how I might best do this? Use the string length... ${pp.sourceFile[pp.sourceFile?length-6..pp.sourceFile?length-5]} If it is needed often, then define a function for it: <#function getLocalCode s> <#return s[s?length-6..s?length-5]> </#function> ... ${getLocaleCode(pp.sourceFile)} -- Best regards, Daniel Dekany |