微信扫一扫联系
 
判断字符串中是否包含中文字符
发布:2021/8/4 11:42:00
     public static bool StrIsChinese(string src)
        {
            if(string.IsNullOrEmpty(src))
                return false;
            int length = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(src).Length;
            if (length > src.Length)
            {
                return true;
            }
            return false;

        }


由于中文字符占用的字节数是2或者3个,英文字符占用的字节数是1,因此转换成字节后,如果有中文字符,那么字节长度会大于字符串长度