Within Python I can use:
test = """My "cute" string"""
Where the double quotes get escaped. Is there a way that I can emulate this within Java without using escape slashes?
I don't see a reason not to escape ", but.. you can do:
System.out.println((char)34+"Some Text"+(char)34); //See ASCII table for more information
Output >> "Some Text"
If you don't need an escape, you should use string concatenation such as:
test = '"' + "My " + '"' + "cute" + '"' + " string" + '"';
Or using StringBuffer to append " character if you want.
Another way to do that is using String.format:
test = String.format("%1$sMy %1$scute%1$s string%1$s", '"');
Which replaces %1$s by your give "quote" later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With