Somnath Guha
Somnath Guha

Reputation: 21

Issue with Double Quotes in java

I am getting three types of value from the database when I am fetching value from a field.

All values are with double quotes. Those values are "Fitness Head, Fiteness " Head and Fitness Head". I have to replace all double quotes with double double quotes using Java. What will be the java code to do that?

Thanks, Somnath

Upvotes: 1

Views: 1631

Answers (4)

Einar
Einar

Reputation: 3317

What about this:

String newValue = oldValue.replace("\"", "\"\"");

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114847

Replacing single double quotes with double double quotes:

"abc\"def".replace("\"", "\"\"")

Upvotes: 0

Oleg Pavliv
Oleg Pavliv

Reputation: 21192

Use String.replace

For example

String doubleQuotes = "\"Fitness head";
doubleQuotes.replace("\"", "\"\"");

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122468

You don't need to replace double quotes anywhere if you are using JDBC to insert/fetch the values - this is all taken care of as long as you use PreparedStatements and placeholders.

See this tutorial.

Upvotes: 3

Related Questions