views:

69

answers:

2

I think this question may be fairly evident from the title alone: I am a C# developer who often uses @ before a string literal to make it more readable (e.g. string drive = @"C:\")

I am in the process of scripting out a lot of my processes (using the wonderful V8 for .Net) and I am wondering whether there's a similar feature in JavaScript?

+5  A: 

No, unfortunately there is no such feature. In JavaScript you can enclose strings in double quotes "..." or in single quotes '...', but in both cases you will have to escape that quote character as well as the backslash.

Timwi
I have sadly come to this conclusion too, Timwi. Thanks.
Phil Whittington
A: 

It's not what you're after, but you can have a string that spans multiple lines like so

var s = "hello\
         world";

Although this isn't part of the standard, so your engine might not support it.

I found out about it here: http://helephant.com/2007/05/spanning-javascript-strings-across-multiple-lines/

Matt Ellen
If you *know* that it’s not what he’s after, perhaps you shouldn’t have posted it as an answer?
Timwi
It _does part_ of what he wants so I thought it _might_ be helpful
Matt Ellen
@Matt Ellen - be serious. It's not even part of what he wants. It isn't even related by a country mile.
Joel Etherton
Thanks Matt. What I really want is a way of storing strings in the .js which are as intuitive as possible. My end users are computer literate but not developers and the end game is for them to edit parameters at will. I can always pull them out into a .xml but would rather keep params and business logic together. Will bear in mind the multiline for other topics, though.
Phil Whittington
@Joel, it allows you to split strings over more than one line which is part of what the @ does for c# strings.
Matt Ellen
@Phil Whittington: sorry I couldn't be more helpful.
Matt Ellen