Created
December 14, 2014 04:31
-
-
Save ollien/1c242ef10bc7929bad36 to your computer and use it in GitHub Desktop.
Twitter Percent Encode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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