I want to keep track of word usage in group chat using the MySQL database. The message sent in the insertword method is an XML string currently. The XML string may contain special characters such as If my message is: How can I convert it to: My code apos 2 times and 2 times how do i fix it? Try adding double quote matches Edit after comments & amp; Apos; and
& amp; Quot; . What is a better way to use String.replace to convert XML formatted strings in general?
I & amp; Apos; I bad, but they are & amp; Apos; ; & Quot; Good & amp; Quot;
I'm bad, but they are not "good"
pattern p = Pattern.compile ("[\\ w '] +"); Prepared position entry WordStmt = connection.prepareStatement ("Include words (word, count) values (?, 1)" + "duplicate key update calculation = count + 1"); Public Zero insert word (string msg) {msg = msg.toLowerCase (); Try {MATTTER M = p.matcher (msg); Whereas (m.find ()) {string word = msg.substring (m.start (), m.end ()); InsertWordStmt.setString (1, word); InsertWordStmt.executeUpdate (); }} Hold (SQLException e) {e.printStackTrace (); }}
Pattern P = Pattern.compile ("[\ [w \"] + ");
Place of msg (msg) to replace toLowerCase () instead of ("& amp;" "" ""). ("& Amp; Bid,", "\" ");
Comments
Post a Comment