Tae-Sung Shin
Tae-Sung Shin

Reputation: 20620

What's the counterpart in Java of C#'s @ string literal?

C# has the @ string literal to flexibly handle escape characters in strings. Is there anything like that in Java?

Upvotes: 5

Views: 1432

Answers (4)

Peter Lawrey
Peter Lawrey

Reputation: 533620

Java supports path separators from UNIX which don't need to be escaped. e.g.

"c:/my/file.txt" 

works fine on windows (and unix if you have a directory called c:)

The chose to use \ rather than / as a path separator like just about every other operating system before or since, is a pet hate of mine. ;) http://en.wikipedia.org/wiki/Backslash

Upvotes: 2

Tudor
Tudor

Reputation: 62449

If only I had a nickle for every time I need this in Java...

If you're doing a Regex operation consider Pattern.quote as a replacement.

Upvotes: 2

Jim Rush
Jim Rush

Reputation: 4163

There isn't. You'll need to escape your strings.

Upvotes: 6

SLaks
SLaks

Reputation: 887657

This is called a verbatim string literal.
Java does not have such a feature.

Upvotes: 4

Related Questions