Example:

String str1 = "Строка со "словом" в кавычках"; 

How to correctly insert a quote character (")?

  • str1 = 'String with the word' in quotes'; - alexkad
  • eight
    @alexkad, this is not javascript, but java. it doesn't work here. - Vladyslav Matviienko
  • 2
    @kaaa, this is called character escaping. - Vladyslav Matviienko

5 answers 5

 final char dm = (char) 34; final String string = "STRING: " + dm + " string " + dm; System.out.println(string); 

Conclusion:

STRING: "string"

  • I did not understand at all, but why were you zaminusovali? Everything worked fine for me. - Andrew Kachalin

The most standard method used in many languages, including Java, is escaping with the \ character:

 String myString = "Строка со \"словом\" в кавычках"; 
  • This is also called escape symbol - Barmaley
  • Thank you, it works, but the task has become more complicated. Before the quotes, you also need to put a slash + "<IMG SRC = \" file: // "+ - kaaa
  • one
    solved in a similar way - DreamChild
  • Yes, really - kaaa
  • extra quotes at the end of the string - TimurVI
 String str1 = "Строка со \"словом\" в кавычках"; 

    Yes, there is, add before each character that you want to escape \ . For example, to display "C: \\\folder\\\folder1\" on the screen, add "screen" in front of each character like this:

     System.out.println("\"C: \\\\\\\folder\\\\\\\folder1\\\\\""); 
        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); 
      • Solution of the problem with JavaRush, right? Is there a "normal" way to escape quotes? - Dunaevsky Maxim
      • @Dunaevsky Maxim, Is the screening symbol not normal for shielding? :) - Isaev