How to enter quotes in Java string?

I want to initialize String in Java, but this string must include quotation marks; for example: "ROM" . I tried:

 String value = " "ROM" "; 

but that will not work. How to include " in a string?

+91
java string escaping quotes
Aug 24 '10 at 17:14
source share
9 answers

In Java, you can escape quotes with \ :

 String value = " \"ROM\" "; 
+182
Aug 24 '10 at 17:16
source share

Not sure which language you are using (you did not specify), but you have to "escape" from the quotation mark using the backslash: "\"ROM\""

+13
Aug 24 '10 at 17:16
source share

Just exit the quotes:

 String value = "\"ROM\""; 
+12
Aug 24 '10 at 17:16
source share

Regarding your comment after Ian Henry’s reply, I’m not quite sure that I understand what you are asking.

If it comes to adding double quotes to a string, you can combine double quotes into your string, for example:

 String theFirst = "Java Programming"; String ROM = "\"" + theFirst + "\""; 

Or, if you want to do this with a single String variable, this will be:

 String ROM = "Java Programming"; ROM = "\"" + ROM + "\""; 

Of course, this actually replaces the original ROM, since Java strings are immutable.

If you want to do something like turning a variable name into a String, you cannot do it in Java, AFAIK.

+12
Aug 24 '10 at 17:33
source share

\ = \\

"= \"

new line = \r\n OR \n\r OR \n (OS dependent) bun usually \n enough.

taabulator = \t

+7
Sep 24 '13 at 12:02
source share

In Java, you can use the char value with ::

 char quotes ='"'; String strVar=quotes+"ROM"+quotes; 
+3
Sep 24 '13 at 11:59 on
source share

Look at this ... call from anywhere.

 public String setdoubleQuote(String myText) { String quoteText = ""; if (!myText.isEmpty()) { quoteText = "\"" + myText + "\""; } return quoteText; } 

apply double quotes to a non-empty dynamic string. Hope this will be helpful.

+1
May 23 '15 at 10:59
source share

Here is a complete Java example:

 public class QuoteInJava { public static void main (String args[]) { System.out.println ("If you need to 'quote' in Java"); System.out.println ("you can use single \' or double \" quote"); } } 

Here is the PUT output: -

 If you need to 'quote' in Java you can use single ' or double " quote 

enter image description here

0
Aug 18
source share

Suppose the ROM is a string variable that is equal to "strval" you can just do

 String value= " \" "+ROM+" \" "; 

it will be saved as

 value= " "strval" "; 
-four
Apr 03 '17 at 9:40 on
source share



All Articles