fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. String s = "明昏昐";
  7. Pattern p = Pattern.compile("&#([0-9]+);");
  8. Matcher m = p.matcher(s);
  9. while (m.find()) {
  10. m.appendReplacement(b, "");
  11. b.append((char) Integer.parseInt(m.group(1)));
  12. }
  13. m.appendTail(b);
  14. s = b.toString();
  15. System.out.println(s);
  16.  
  17. s = "あいう";
  18. b = new StringBuffer();
  19. for (int i = 0; i < s.length(); i++) {
  20. b.append("&#" + (int) s.charAt(i) + ";");
  21. }
  22. s = b.toString();
  23. System.out.println(s);
  24. }
  25. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
明昏昐
&#12354;&#12356;&#12358;