encode string in GB2312 - Android Internationalization

Android examples for Internationalization:Chinese

Description

encode string in GB2312

Demo Code

import android.text.TextUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;

public class Main{

    public static String encodeGB(String string) {
        String split[] = string.split("/");
        for (int i = 1; i < split.length; i++) {
            try {
                split[i] = URLEncoder.encode(split[i], "GB2312");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();/*from   w ww .  j  av a2  s.  c  om*/
            }
            split[0] = split[0] + "/" + split[i];
        }
        split[0] = split[0].replaceAll("\\+", "%20");
        return split[0];
    }

}

Related Tutorials