Java String to Chinese GB2312 toGb2312(String str)

Here you can find the source of toGb2312(String str)

Description

to Gb

License

LGPL

Declaration

public static String toGb2312(String str) 

Method Source Code

//package com.java2s;
/**//from w w  w . j  a  v  a 2  s.co m
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance(). <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

public class Main {

    public static String toGb2312(String str) {
        try {
            return new String(str.getBytes("ISO8859_1"), "GB2312");
        } catch (Exception e) {
            return str;
        }
    }

    public static String toGB2312(String str) {
        try {
            return new String(str.getBytes("GB2312"), "ISO8859_1");
        } catch (Exception e) {
            return str;
        }
    }
}

Related

  1. isGB2312(char c)
  2. toGB2312(String s)
  3. toGB2312(String s)