You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Udo Borkowski <Ud...@gmx.de> on 2003/10/10 20:38:40 UTC

Using Backslash in Strings

How can I assign the String "\." (backslash-dot) to a property?

When I use

    #set($foo= "\.");

I get an 

    Lexical error ... Encountered: "." (46), after : "\"\\"

When I try to escape the backslash, ie write
    
    #set($foo= "\\.")

$foo contains backslash-backslash-dot.

Any idea?

Thanks,
Udo

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Using Backslash in Strings

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On Friday, October 10, 2003, at 02:38 PM, Udo Borkowski wrote:

> How can I assign the String "\." (backslash-dot) to a property?
>
> When I use
>
>     #set($foo= "\.");
>
> I get an
>
>     Lexical error ... Encountered: "." (46), after : "\"\\"
>
> When I try to escape the backslash, ie write
>
>     #set($foo= "\\.")
>
> $foo contains backslash-backslash-dot.
>
> Any idea?

This happens because "" 'renders' the contents of the string and \ is 
the start of an escape for a reference.  This is a bug, I'm sure, but 
there's a quick work-around - just do :

#set($foo = '\.')

The single quote string means "don't interpolate this"...

>
> Thanks,
> Udo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geirm@optonline.net


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org