get Chinese Character - Android Internationalization

Android examples for Internationalization:Chinese

Description

get Chinese Character

Demo Code

/**/*  ww  w .  ja  v a 2  s  .c  om*/
 * Project Name:JZGPingGuShi
 * File Name:ChineseUtil.java
 * Package Name:com.gc.jzgpinggushi.uitls
 * Date:2014-9-1????10:37:21
 * Copyright (c) 2014, wangyd523@gmail.com All Rights Reserved.
 *
 */
//package com.java2s;
import java.io.UnsupportedEncodingException;

public class Main {

    public static int getCnAscii(char cn) {
        byte[] byteAscii;
        try {
            byteAscii = (String.valueOf(cn)).getBytes("GBK");
        } catch (UnsupportedEncodingException ex) {
            return 0;
        }
        if (byteAscii == null || byteAscii.length > 2
                || byteAscii.length <= 0) {
            return 0;
        }
        if (byteAscii.length == 1) {
            return byteAscii[0];
        }
        if (byteAscii.length == 2) {
            int iHightByte = 256 + byteAscii[0];
            int iLowByte = 256 + byteAscii[1];
            int iAscii = (256 * iHightByte + iLowByte) - 256 * 256;
            return iAscii;
        }
        return 0;
    }
}

Related Tutorials