Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am retrieving data from a database, where the field contains a String with HTML data. I want to replace all of the double quotes such that it can be used for parseJSON of jQuery.

Using Java, I am trying to replace the quotes using..

details.replaceAll(""",""");
  //details.replaceAll(""","&quote;"); details.replaceAll(""","&#34");

The resultant string doesn't show the desired change. An O'Reilly article prescribes using Apache string utils. Is there any other way??

Is there a regex or something that I could use?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
657 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here's how

String details = "Hello "world"!";
details = details.replace(""",""");
System.out.println(details);               // Hello "world"!

Note that strings are immutable, thus it is not sufficient to simply do details.replace(""","""). You must reassign the variable details to the resulting string.


Using

details = details.replaceAll(""","&quote;");

instead, results in

Hello &quote;world&quote;!

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...