Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have the '@' character to escape string quotes?

My string has double quotes in it, in C# I would do:

string blah = @"this is my ""text";

how would I do that in Java?

like image 577
mrblah Avatar asked Jan 07 '10 06:01

mrblah


2 Answers

Yes* (since September 2019) but it used different sintax. “”” (three double-quote marks).

*In more recent java versions (+13 in preview, +15 as production ready), mostly equivalent can be achieved with the java text blocks.

String html = """         
            <xml>
                <ody>
                    <pan>example xml </pan>
                </ody>
            </xml>""";

https://docs.oracle.com/en/java/javase/13/text_blocks/index.html

like image 149
João Avatar answered Oct 20 '22 16:10

João


No. Such a feature is not available in Java.
From the Sun docs:

When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. For example, if you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. To print the sentence

She said "Hello!" to me.

you would write

System.out.println("She said \"Hello!\" to me.");
like image 40
codaddict Avatar answered Oct 20 '22 14:10

codaddict