Get Chinese String in GB2312 from another String - Java Internationalization

Java examples for Internationalization:Chinese

Description

Get Chinese String in GB2312 from another String

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String str = "java2s.com";
        System.out.println(GetCNString(str));
    }//www. ja v a  2 s  .co  m

    public static String GetCNString(String str) {
        if (str == null || "".equals(str)) {
            return "";
        }

        try {
            return new String(str.trim().getBytes("ISO-8859-1"), "GB2312");
        } catch (Exception ex) {
        }

        return "";
    }
}

Related Tutorials