Skip to content

Instantly share code, notes, and snippets.

@beefy
Last active April 15, 2016 02:33
Show Gist options
  • Save beefy/a2334905eed3bf623b68642cc13899dc to your computer and use it in GitHub Desktop.
Save beefy/a2334905eed3bf623b68642cc13899dc to your computer and use it in GitHub Desktop.
encoding Unicode (including emojis) for web server
String[] msg_chars = new String[msg_text.length()];
for(int i=0; i < msg_text.length(); i++) {
msg_chars[i] = "\\" +String.valueOf(String.format("\\u%04x", (int) msg_text.charAt(i)));
}
msg_text = ""
for(int i=0; i < msg_chars.length; i++) {
msg_text += msg_chars[i];
}
try {
encoded_msg = URLEncoder.encode(msg_text, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment