开发者

Issue with Double Quotes in java

开发者 https://www.devze.com 2023-04-06 08:06 出处:网络
I am getting three types of value from the database when I am fet开发者_如何学Goching value from a field.

I am getting three types of value from the database when I am fet开发者_如何学Goching 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


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.


Use String.replace

For example

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


Replacing single double quotes with double double quotes:

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


What about this:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消