Java String Single Byte Check isAllSingleByte(String str)

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

Description

is All Single Byte

License

Apache License

Declaration

public static boolean isAllSingleByte(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static boolean isAllSingleByte(String str) {
        if (str != null) {
            int len = str.length();
            int i = 0;
            byte[] b;
            try {
                b = str.getBytes("GBK");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();//from  www.j  av  a2  s .  com
                b = str.getBytes();
            }
            while (i < len && b[i] < 128) {
                i++;
            }
            if (i < len)
                return false;
            return true;
        }
        return false;
    }
}