java中双引号的问题
当我从字段中获取值时,我从数据库中获取三种类型的值。
所有值都带有双引号。这些值为“健身头
、健身“头
和健身头”
。我必须使用 Java 代码将所有双引号替换为 double 双引号,
谢谢, 索姆纳特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用 JDBC 插入/获取值,则无需在任何地方替换双引号 - 只要您使用
PreparedStatement
和占位符,这一切就可以解决。请参阅本教程。
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
PreparedStatement
s and placeholders.See this tutorial.
使用 String.replace
例如
Use String.replace
For example
将单双引号替换为双双引号:
Replacing single double quotes with double double quotes:
怎么样:
String newValue = oldValue.replace("\"", "\"\"");
What about this:
String newValue = oldValue.replace("\"", "\"\"");