0

I want to print an attribute of a class I am making , but I need it to be printed inside quotes " ".

I know it has something to with Escape Sequences but a similar post I found suggested using "\"Hello\"" for example to print "Hello"... My case is a bit more complicated cause I don't know beforehand the value of the attribute I want to print. So how can I do this?

Oleksandr Pyrohov
  • 14,685
  • 6
  • 61
  • 90

2 Answers2

2

Why don't make a function that make any String into a Quote. Exanple

public static String quotePrinter(String myQuote)
{
    return "\"" +myQuote+ "\"";
}

    String myQuote = "Hello World";
    System.out.println(quotePrinter(myQuote));

And the output

"Hello World"
Gatusko
  • 2,503
  • 1
  • 17
  • 25
0

Not sure if i understand corretly want you want but take a look at the answers from @ataylor and @Martin Törnwall How to format strings in Java for String interpolation

GabLeg
  • 352
  • 4
  • 14