Convert ISO-8859-1 string To UTF-8 string - Android java.lang

Android examples for java.lang:String UTF-8

Description

Convert ISO-8859-1 string To UTF-8 string

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;

public class Main{

    public static String convertToUTF8(String input) {
        String converted;/*from   ww  w .  j a va  2  s.  co m*/
        try {
            // From http://stackoverflow.com/questions/9069799/android-json-charset-utf-8-problems
            converted = new String(input.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            Log.e(TAG,
                    "Unable to convert given string \"" + input
                            + "\" to UTF-8 from ISO-8859-1 due to: "
                            + ex.getMessage());
            converted = input;
        }
        return converted;
    }

}

Related Tutorials