Convert string from one charset to another charset - Android java.lang

Android examples for java.lang:String Unicode

Description

Convert string from one charset to another charset

Demo Code

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Main{

    public static String getEncdDcd(String srcString, String srcCharsetNm,
            String cnvrCharsetNm) {

        String rtnStr = null;/*w ww.  j  a  va  2  s. c  om*/

        if (srcString == null)
            return null;

        try {
            rtnStr = new String(srcString.getBytes(srcCharsetNm),
                    cnvrCharsetNm);
        } catch (UnsupportedEncodingException e) {
            rtnStr = null;
        }

        return rtnStr;
    }

}

Related Tutorials