Skip to content

Instantly share code, notes, and snippets.

@ThanawatMas
Created September 14, 2020 06:26
Show Gist options
  • Save ThanawatMas/f40901244c6292bab726b88b80d95ec7 to your computer and use it in GitHub Desktop.
Save ThanawatMas/f40901244c6292bab726b88b80d95ec7 to your computer and use it in GitHub Desktop.
Read Thai Character in DB
private static String convert2Round(String thaiString) throws UnsupportedEncodingException {
String result = "";
String[] charset = {"ISO-8859-1", "UTF-8", "TIS-620"};
for(int i=0; i<charset.length; i++) {
for(int j=0; j<charset.length; j++) {
if(charset[i].equals(charset[j])) {
continue;
}
String encode = "Style: algo=" + charset[i] + ">" + charset[j] + "\n";
encode += "Style: result=" + new String(thaiString.getBytes(charset[i]), charset[j]);
result += encode + "\n";
}
}
return result;
}
private String convert3Round(String thaiString) throws UnsupportedEncodingException {
String result = "";
String[] charset = {"ISO-8859-1", "UTF-8", "TIS-620"};
for(int i=0; i<charset.length; i++) {
for(int j=0; j<charset.length; j++) {
for(int k=0; k<charset.length; k++) {
if(charset[i].equals(charset[j]) || charset[j].equals(charset[k]) || charset[k].equals(charset[i])) {
continue;
}
String encode = "Style: algo=" + charset[i] + ">" + charset[j] + ">" + charset[k] + "\n";
encode += "Style: result=" + new String((new String(thaiString.getBytes(charset[i]), charset[j])).getBytes(charset[k]));
result += encode + "\n";
}
}
}
return result;
}
private void printOutEnDeProblem(String input) throws UnsupportedEncodingException {
String result2round = convert2Round(input);
String result3round = convert3Round(input);
System.out.println(result2round + result3round);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment