• 判断一个字符串全是汉字或者全是数字


                        bool bl = System.Text.RegularExpressions.Regex.IsMatch(name, @"[\u4e00-\u9fa5]+$");
                        if (!bl)
                        {
                            ("姓名只能为汉字");
                        }
     private static bool IsNumeric(string str) //接收一个string类型的参数,保存到str里
            {
                if (str == null || str.Length == 0)    //验证这个参数是否为空
                    return false;                           //是,就返回False
                ASCIIEncoding ascii = new ASCIIEncoding();//new ASCIIEncoding 的实例
                byte[] bytestr = ascii.GetBytes(str);         //把string类型的参数保存到数组里
    
                foreach (byte c in bytestr)                   //遍历这个数组里的内容
                {
                    if (c < 48 || c > 57)                          //判断是否为数字
                    {
                        return false;                              //不是,就返回False
                    }
                }
                return true;                                        //是,就返回True
            }
  • 相关阅读:
    HDU 1429
    HDU 1622
    HDU 3335
    HDU 4160
    HDU 1350
    HDU 5086
    HDU 1300
    HDU 3047
    HDU 3038
    HDU 5100
  • 原文地址:https://www.cnblogs.com/zwnet/p/2778558.html
Copyright © 2020-2023  润新知