Is string In GB2312 - CSharp System.Globalization

CSharp examples for System.Globalization:Chinese

Description

Is string In GB2312

Demo Code


using System.Text;
using System;/*  w w w. j ava  2 s.c  o m*/

public class Main{
        public static bool IsInGB2312(string str)
        {
            if ((str == null) || (str == ""))
            {
                return false;
            }
            for (int i = 0; i < str.Length; i++)
            {
                if (!IsInGB2312(str[i]))
                {
                    return false;
                }
            }
            return true;
        }
        public static bool IsInGB2312(char c)
        {
            byte[] bytes = gbkEncoding.GetBytes(new char[] { c });
            if (((bytes.Length == 2) && (0xb0 <= bytes[0])) && ((bytes[0] <= 0xf7) && (160 <= bytes[1])))
            {
                return (bytes[1] <= 0xfe);
            }
            return false;
        }
}

Related Tutorials