velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <>
Subject Re: How to escape ","
Date Tue, 13 Jul 2004 08:07:32 GMT
use sigle quotes to avoid parsing the string!

sliver wrote:
> I need to escape the character "," in a format string.
> Line looks like this:
> tool.formatValue(12344566, "#,##0.00")
  ^ I guess you missed the context variable reference declarator character: $

$tool.formatValue(12344566, '#,##0.00')

> How do I can escape the "," because I always get an error on this line.

Other way is to use the bakslash escape character, but its
tricky and somewhat buggy in the velocity implementation (beware of
consecutive \\s! - see the velocity users guide):

$tool.formatValue(12344566, "\#,\#\#0.00")

Appart from the single-quoted, non-parsed strings; if you need
the string with interpolated variables, use the full functional
poor-man's escaping replacement. Example:

#set( $Q = '#' )
#set( $decimals = '00' )
$tool.formatValue(12344566, "$Q,$Q${Q}0.$decimals")
## Noticed the last ${Q} with braces?
## - Its to separate the context variable reference from the following digit.

Hope this helps,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message