This discussion is archived
4 Replies Latest reply: Jan 11, 2006 7:30 PM by 843853 RSS

String escaping in Java

843853 Newbie
Currently Being Moderated
Hi there,
I've been programming in Java for 5 years now, and there is one feature which will make my life alot easier.
I'm talking about string escaping (a la c#'s @"c:\Docs\Source\a.txt", or python's single quoted strings).

What do you think about it?
  • 1. Re: String escaping in Java
    843853 Newbie
    Currently Being Moderated
    That would be kind of handy, I guess, but if you have a lot of Strings that need escaping hard coded into your application then it is probably because you are designing badly anyway, right?

    Drake
  • 2. Re: String escaping in Java
    843853 Newbie
    Currently Being Moderated
    And to add to that, assuming that a literal backslash represents a file separator is DEFINITELY bad design.

    Drake
  • 3. Re: String escaping in Java
    843853 Newbie
    Currently Being Moderated
    And to add to that, assuming that a literal backslash
    represents a file separator is DEFINITELY bad
    design.

    Drake
    It was just an example...
    Escaping is as useful when using XPaths, Regular expressions, etc...
    Don't pick to the small details :) (And picking to the path seperator (I'm wide aware of the static members of class File) is really nto relevant)

    I agree that most strings should be externalized (it's not a matter of design, just of good programming), but still, some strings will always stay hardcoded.
    (js escaping your '<' in xmls is better???) - mostly when experimenting and writing some 'scratchbook' code.

    The facility for escaping strings in C# and in Python is very useful. Moreover, adding this string escaping mechanism will be backward compatible.

    Any other opinions?
    Thanks :)
  • 4. Re: String escaping in Java
    843853 Newbie
    Currently Being Moderated
    Hi there,
    I've been programming in Java for 5 years now, and
    there is one feature which will make my life alot
    easier.
    I'm talking about string escaping (a la c#'s
    @"c:\Docs\Source\a.txt", or python's single quoted
    strings).

    What do you think about it?
    It could be handy, but personally I don't think it's a problem that needs fixing or even a situation that needs improving.
    My personal opinion is there is not sufficient gain in it worth to introduce a new syntax element. But it's of course up to the language designers to make that judgement.