0

I want to print following line from which A1 is string variable which is changing continuously.

test: "a1" is mapped to Product. Cannot delete

I used the following code to save the message in a variable expectedMsg2 and print expectedMsg2 but I am unable to print A1 in double quotes, how do I print double quote? What is syntax for this?

String expectedMsg2 = "test: "+A1+ " is mapped to Product. Cannot delete";
Fabricio Lemos
  • 2,905
  • 2
  • 31
  • 31
Prasad Din
  • 55
  • 2
  • 3
  • 12

4 Answers4

3
String expectedMsg2 = "test: \""+A1+ "\" is mapped to Product. Cannot delete";
Blekit
  • 663
  • 4
  • 7
1

You can use escape sequence i.e. backward slash(\) to avoid special characters..

For Eg:

System.out.print("\"Hello\"");

Output:

"Hello"

Kamlesh Arya
  • 4,864
  • 3
  • 21
  • 28
1

With java \ will Try something like

String expectedMsg2 = "test: \" "+A1+ "\" is mapped to Product. Cannot delete";

Tutorial from oracle on Escaping

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

Try this

System.out.println("\"Double Quote is Printed\"");

outPut:

"Double Quote is Printed"
Raj
  • 600
  • 1
  • 5
  • 18