get Chinese string's Length - Android Internationalization

Android examples for Internationalization:Chinese

Description

get Chinese string's Length

Demo Code

import android.content.Context;
import android.location.Location;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main{

    public static int getChineseLength(String value) {
        int valueLength = 0;
        String chinese = "[\u0391-\uFFE5]";
        for (int i = 0; i < value.length(); i++) {
            String temp = value.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 1;/*from  w  w  w .  jav a2s. c  om*/
            }
        }
        return valueLength;
    }

}

Related Tutorials