Created
October 18, 2016 14:42
-
-
Save jtryan/1c86c66e9b5f5f1f4cc6cddd62b4fe09 to your computer and use it in GitHub Desktop.
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
// Return HTML Entity code equivalents for any special characters | |
public static String HTMLEntityEncode( String input ) { | |
StringBuffer sb = new StringBuffer(); | |
for ( int i = 0; i < input.length(); ++i ) { | |
char ch = input.charAt( i ); | |
if ( ch>='a' && ch<='z' || ch>='A' && ch<='Z' || ch>='0' && ch<='9' ) { | |
sb.append( ch ); | |
} else { | |
sb.append( "&#" + (int)ch + ";" ); | |
} | |
} | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment