Skip to content

Instantly share code, notes, and snippets.

@javapriyan
Created June 8, 2017 06:12
Show Gist options
  • Select an option

  • Save javapriyan/e258195a6f9c8bb87121138901c9dfd7 to your computer and use it in GitHub Desktop.

Select an option

Save javapriyan/e258195a6f9c8bb87121138901c9dfd7 to your computer and use it in GitHub Desktop.
package com.demo.utf;
import org.apache.commons.lang.StringEscapeUtils;
/**
* Created by kumaran on 7/6/17.
*/
public class UTFTest {
public static void main(String[] args) {
//String s = StringEscapeUtils.escapeHtml("INR is ₹ < \" \' ");
String s = "INR is ₹ ₠ ₯ ₸ ₵ € ₤ < ® © Ø ¥ μ £ å ä ₤ € \" \' ";
System.out.println(s);
char [] letters = s.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i =0 ;i<letters.length;i++) {
char c = letters[i];
//range 20A0 to 20CF is for currencies http://www.unicode.org/charts/PDF/U20A0.pdf
sb.append(new String(""+c).replaceAll("[\u20A0-\u20CF]+|[\u0080-\u00FF]+","&#"+Integer.toHexString(c)));
}
System.out.println("final formatted Str " + sb.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment