How do I insert a double quote character in a string?
Example:
String str1 = "Строка со "словом" в кавычках";
How do I insert the quotation mark character (") correctly?
10
5 answers
final char dm = (char) 34;
final String string = "STRING: " + dm + " string " + dm;
System.out.println(string);
Conclusion:
STRING: " string "
0
Author: And, 2017-11-12 07:49:20
The most standard method used in many languages, including Java is escaping with the {[1] character]}:
String myString = "Строка со \"словом\" в кавычках";
33
Author: DreamChild, 2017-11-12 07:28:17
String str1 = "Строка со \"словом\" в кавычках";
11
Author: Павел Вершинин, 2015-04-02 08:23:40
Yes, there is, you add before each character that needs to be escaped \
.
For example, to display "C: \\\folder\\\folder1\"
, you need to add a "screen" before EACH character like this:
System.out.println("\"C: \\\\\\\folder\\\\\\\folder1\\\\\"");
2
Author: Артём, 2017-03-31 10:07:42
String x = "\\";
String y = "\"";
System.out.println("It's Windows path: " + y + "C:" + x + "Program Files" + x + "Java" + x + "jdk1.7.0" + x + "bin" + y);
System.out.println("It's Java string: " + x + y + "C:" + x + x + "Program Files" + x + x + "Java" + x + x + "jdk1.7.0" + x + x + "bin" + x + y);
1
Author: messeng, 2016-01-24 21:12:57