zoukankan      html  css  js  c++  java
  • c# 判断非法字符

    /// <summary>
            /// 判断是否是非法字符
            /// </summary>
            /// <param name="str">判断是字符</param>
            /// <returns></returns>
            public static Boolean isLegalNumber(string str)
            {
                char[] charStr = str.ToLower().ToCharArray();
                for (int i = 0; i < charStr.Length; i++)
                {
                    int num = Convert.ToInt32(charStr[i]);
                    if (!(IsChineseLetter(num)|| (num >= 48 && num <= 57) || (num >= 97 && num <= 123) || (num >= 65 && num <= 90) || num == 45))
                    {
                        return false;
                    }
                }
                return true;
            }
    
    
            /// <summary>
            /// 判断字符的Unicode值是否是汉字
            /// </summary>
            /// <param name="code">字符的Unicode</param>
            /// <returns></returns>
            protected static bool IsChineseLetter(int code)
            {
                int chfrom = Convert.ToInt32("4e00", 16);    //范围(0x4e00~0x9fff)转换成int(chfrom~chend)
                int chend = Convert.ToInt32("9fff", 16);
    
                if (code >= chfrom && code <= chend)
                {
                    return true;     //当code在中文范围内返回true
    
                }
                else
                {
                    return false;    //当code不在中文范围内返回false
                }
    
                return false;
            }
  • 相关阅读:
    【npm】mac下node环境搭建
    pair求解迷宫的最短路径(bfs)
    dos窗口启动关闭Mysql
    二维差分模板
    一维差分模板
    DOS命令
    迷宫搜索dfs实现
    DFS 迷宫问题
    BFS广搜解决迷宫问题(跟着B站大佬手撸)
    蓝桥杯省赛模拟赛
  • 原文地址:https://www.cnblogs.com/liuxinls/p/3076015.html
Copyright © 2011-2022 走看看