public class StringFormatter {
public static String convertUTF8ToString(String s) {
String out = null;
try {
out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
public static String convertStringToUTF8(String s) {
String out = null;
try {
out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
}
You can convert your string using the StringFormatter class to your code.
Do you want to convert to UTF-8:
String normal="This normal string".
String utf=StringFormatter.convertStringToUTF8(normal);
You want to convert UTF-8 to normal format:
String normal=StringFormatter.convertUTF8ToString(normal);
source
share