I'm trying to add double quotes in a string using the unicode, but when I do so i get the compilation time error.
String unicCode = "\u0022"; //This line gives a compile time error.
The compilation error is that I get is
String literal is not properly closed by a double-quote.
Could some one help me to understand what are the escape characters required to be used to append a unicode of a double quotation mark (").
public static void main(String[] args) {
String quote = "\u005c\u0022";
System.out.println(quote);
}
Output
"
public static void main(String[] args) {
String quote = "\u005c\u0022" + "abc" + "\u005c\u0022";
System.out.println(quote);
}
Output
"abc"
If you wanted to put the two double quote chars into the string literal, you can do it with normal escape sequences. But you can't do with Unicode escapes
because Java provides no special treatment for Unicode escapes within string literals.
String quote = "\"";
// We can't represent the same string with a single Unicode escape.
// \u0022
has exactly the same meaning to the compiler as ".
// The string below turns into """
: an empty string followed
// by an unterminated string, which yields a compilation error.
String quote = "\u0022";
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