zoukankan      html  css  js  c++  java
  • 常用方法一:随机数生成、检测非法字符、判断数字格式、是否为空、枚举值转化为数组

     这是我项目里面用到的用来检测或是处理字符,随机生成数字等的一个通用类文件:

      1using System;
      2using System.Collections.Generic;
      3using System.Text.RegularExpressions;
      4using System.Text;
      5
      6
      7namespace InsApp.word
      8{
      9    /// <summary>
     10    /// string CreateRandomCode(int codeCount)  根据长度生成随机的数字和字母
     11    /// bool toFilter(string thePara)           检测非法字符,如果参数是空/包含非法字符,返回false/否则返回 true
     12    /// bool CheckNumber(string GetNum)         判断是否是数字格式
     13    /// bool CheckNumberRegx(string GetNum)     判断是否是正负数字含小数
     14    /// bool CheckNullstr(string Getstr)        判断是否是空值null 返回true || false
     15    /// </summary>

     16    public class CreateCode
     17    {
     18        生成随机的数字和字母 codeCount是希望生成的长度
     45
     46        判断是否是数字格式
     65
     66        检测非法字符,防止sql注入
    104
    105        bool CheckNullstr(string Getstr)判断是否是空值
    131
    132        bool CheckNumberRegx(string GetNum)正则表达式 判断是否是正负数字含小数
    151
    152        用C#截取指定长度的中英文混合字符串
    178
    179        数字和字母随机数
    204
    205        字母随机数
    230
    231        日期随机函数
    257
    258        生成GUID
    269    }

    270}

    271

    由枚举值生成数组,可以用于绑定到ComboBox上或者DropDownList。

    class Utils
    {
        
    public static object[] GetEnumValues(Type type)
        {
            List
    <object> list = new List<object>();
            
    for (int i = 0; ; i++)
            {
                
    string val = Enum.GetName(type, i);
                
    if (!string.IsNullOrEmpty(val))
                    list.Add(val);
                
    else
                    
    break;
            }

            
    return list.ToArray();
        }
    }

    使用:

    object[] list = Utils.GetEnumValues(typeof(ChartType))
  • 相关阅读:
    前端安全-XSS攻击
    leetcode-0003 无重复字符的最长子串
    leetcode-0002 两数相加
    leetcode-0001 两数之和
    数据结构篇-数组(TypeScript版+Java版)
    前端性能优化(一)-- 文件的压缩与合并
    《深入浅出RxJS》读书笔记
    python工具函数
    [其他]Ubuntu安装genymotion后unable to load VirtualBox engine
    [linux]CentOS无法使用epel源
  • 原文地址:https://www.cnblogs.com/Dlonghow/p/1232304.html
Copyright © 2011-2022 走看看