Skip to content

Instantly share code, notes, and snippets.

@ollien
Created December 14, 2014 04:31
Show Gist options
  • Save ollien/1c242ef10bc7929bad36 to your computer and use it in GitHub Desktop.
Save ollien/1c242ef10bc7929bad36 to your computer and use it in GitHub Desktop.
Twitter Percent Encode
private static String percentEncode(String s){
String result = "";
for (int i=0; i<s.length(); i++){
char check = s.charAt(i);
if (Character.isLetter(check) || Character.isDigit(check) || check == '-' || check=='.' || check=='_' || check == '~' ){
result+=check;
}
else{
result+=("%"+Integer.toHexString(check));
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment