Android乱码类型判断

来源:互联网 发布:win域名无法备案 编辑:程序博客网 时间:2024/06/07 06:41
public static void testCharset(String datastr){
                try {
                        String temp = new String(datastr.getBytes(), "GBK");
                        Log.v("TestCharset","****** getBytes() -> GBK ******\n"+temp);
                        temp = new String(datastr.getBytes("GBK"), "UTF-8");
                        Log.v("TestCharset","****** GBK -> UTF-8 *******\n"+temp);
                        temp = new String(datastr.getBytes("GBK"), "ISO-8859-1");
                        Log.v("TestCharset","****** GBK -> ISO-8859-1 *******\n"+temp);
                        temp = new String(datastr.getBytes("ISO-8859-1"), "UTF-8");
                        Log.v("TestCharset","****** ISO-8859-1 -> UTF-8 *******\n"+temp);
                        temp = new String(datastr.getBytes("ISO-8859-1"), "GBK");
                        Log.v("TestCharset","****** ISO-8859-1 -> GBK *******\n"+temp);
                        temp = new String(datastr.getBytes("UTF-8"), "GBK");
                        Log.v("TestCharset","****** UTF-8 -> GBK *******\n"+temp);
                        temp = new String(datastr.getBytes("UTF-8"), "ISO-8859-1");
                        Log.v("TestCharset","****** UTF-8 -> ISO-8859-1 *******\n"+temp);
                } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                }
        }
0 0
原创粉丝点击