【c#】DataChecker工具类大全分享
来源:互联网 发布:淘宝点点 编辑:程序博客网 时间:2024/06/07 00:46
- IsEmpty functions
- DataSet
- DataTable
- String
- code1
- code2
- code3
- ICollection
- code1
- code2
- Object
- IsNotEmpty functions
- DataSet
- DataTable
- String
- code1
- code2
- ICollection
- code1
- code2
- Object
- HasEmpty
- AllAreEmpty
- AllAreNotEmpty
- Digit checking
- IsUInt
- IsInt
- IsUDecimal
- IsDecimal
- Chinese checking
- Mail Address check
- MathRelative
- ToSBC-转全角的函数
- ToDBC-转半角的函数
IsEmpty functions
DataSet
/// <summary>/// DataSet is null or empty/// </summary>/// <param name="dataSet">checking DataSet</param>/// <returns>if null or empty, then return<c>true</c>; else return <c>false</c>.</returns>public static bool IsEmpty(DataSet dataSet){ return !(IsNotEmpty(dataSet));}
DataTable
/// <summary>/// DataTable is null or empty/// </summary>/// <param name="dataTable">DataTable.</param>/// <returns>if null or empty, then return<c>true</c><c>true</c>;else return <c>false</c>.</returns>public static bool IsEmpty(DataTable dataTable){ return !(IsNotEmpty(dataTable));}
String
code@1
/// <summary>/// input string is null or String.Empty/// </summary>/// <param name="str">checking string</param>/// <param name="removeSpace">remove front/end spaces or not</param>/// <returns>if null or empty, then return<c>true</c>; else return <c>false</c>.</returns>public static bool IsEmpty(string str, bool removeSpace){ if (str == null) { return true; } if (removeSpace) { return (str.Trim().Length == 0); } return (str.Length == 0);}
code@2
public static bool IsReadEmpty(string str){ return IsRealEmpty(str, true);}
code@3
public static bool IsRealEmpty(string str, bool removeSpace){ if (str == null) { return true; } if (removeSpace) { return (str.Replace(" ", " ").Trim().Length == 0); } return (str.Length == 0);}
ICollection
code@1
/// <summary>/// Determines whether the specified value is empty./// </summary>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if the specified value is empty; otherwise, <c>false</c>./// </returns>public static bool IsEmpty(ICollection value){ return (value == null || value.Count == 0);}
code@2
/// <summary>/// Determines whether the specified value is empty./// </summary>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if the specified value is empty; otherwise, <c>false</c>./// </returns>public static bool IsEmpty<T>(ICollection<T> value){ return (value == null || value.Count == 0);}
Object
/// <summary>/// Determines whether the specified value is empty./// </summary>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if the specified value is empty; otherwise, <c>false</c>./// </returns>public static bool IsEmpty(object value){ if (value == null) { return true; } if (value is string) { return IsEmpty((string)value); } if (value is ICollection) { return IsEmpty((ICollection)value); } if (value is DataSet) { return IsEmpty((DataSet)value); } if (value is DataTable) { return IsEmpty((DataTable)value); } return false;}
IsNotEmpty functions
DataSet
/// <summary>/// data in DataSet/// </summary>/// <param name="dataSet">checking DataSet</param>/// <returns>if null or empty, then return<c>false</c>; otherwise <c>true</c>.</returns>public static bool IsNotEmpty(DataSet dataSet){ if (dataSet == null) { return false; } for (int i = 0; i < dataSet.Tables.Count; i++) { if (IsNotEmpty(dataSet.Tables[i])) { return true; } } return false;}
DataTable
/// <summary>/// data in DataTable/// </summary>/// <param name="dataTable">DataTable.</param>/// <returns>if null or empty, then return<c>false</c>; else return <c>true</c>.</returns>public static bool IsNotEmpty(DataTable dataTable){ if (dataTable == null) { return false; } if (dataTable.Rows.Count > 0) { return true; } return false;}
String
code@1
/// <summary>/// string is null or String.Empty。/// </summary>/// <param name="str">checking string</param>/// <param name="removeSpace">remove front and end spaces or not</param>/// <returns>if null or empty, then return<c>false</c>; else return <c>true</c>.</returns>public static bool IsNotEmpty(string str, bool removeSpace){ return (!IsEmpty(str, removeSpace));}
code@2
/// <summary>/// input string is null or String.Empty,remove the front and end spaces./// </summary>/// <param name="str">checking string</param>/// <returns>if null or empty, then return<c>false</c>; else return <c>true</c>.</returns>public static bool IsNotEmpty(string str){ return IsNotEmpty(str, true);}
ICollection
code@1
/// <summary>/// Determines whether [is not empty] [the specified value]./// </summary>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if [is not empty] [the specified value]; otherwise, <c>false</c>./// </returns>public static bool IsNotEmpty(ICollection value){ return !IsEmpty(value);}
code@2
/// <summary>/// Determines whether [is not empty] [the specified value]./// </summary>/// <typeparam name="T"></typeparam>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if [is not empty] [the specified value]; otherwise, <c>false</c>./// </returns>public static bool IsNotEmpty<T>(ICollection<T> value){ return !IsEmpty(value);}
Object
/// <summary>/// Determines whether [is not empty] [the specified value]./// </summary>/// <param name="value">The value.</param>/// <returns>/// <c>true</c> if [is not empty] [the specified value]; otherwise, <c>false</c>./// </returns>public static bool IsNotEmpty(object value){ return !IsEmpty(value);}
HasEmpty
/// <summary>/// Determines whether the specified args has empty./// </summary>/// <param name="args">The args.</param>/// <returns>/// <c>true</c> if the specified args has empty; otherwise, <c>false</c>./// </returns>public static bool HasEmpty(params object[] args){ foreach (object arg in args) { if (IsEmpty(arg)) { return true; } } return false;}
AllAreEmpty
/// <summary>/// Alls the are empty./// </summary>/// <param name="args">The args.</param>/// <returns></returns>public static bool AllAreEmpty(params object[] args){ foreach (object arg in args) { if (IsNotEmpty(arg)) { return false; } } return true;}
AllAreNotEmpty
/// <summary>/// Alls the are not empty./// </summary>/// <param name="args">The args.</param>/// <returns></returns>public static bool AllAreNotEmpty(params object[] args){ foreach (object arg in args) { if (IsEmpty(arg)) { return false; } } return true;}
Digit checking
IsUInt
/// <summary>/// Decimal and unsigned data/// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool IsUInt(string input){ Regex regUInt = new Regex("^[0-9]+$"); if (!IsNotEmpty(input)) { return false; } Match match = regUInt.Match(input); return match.Success;}
IsInt
/// <summary>/// Decimal integer string./// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool IsInt(string input){ Regex regInt = new Regex("^[+-]?[0-9]+$"); if (!IsNotEmpty(input)) { return false; } Match match = regInt.Match(input); return match.Success;}
IsUDecimal
/// <summary>/// Whether it is an unsigned decimal number, including decimal./// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool IsUDecimal(string input){ Regex regUDecimal = new Regex("^[0-9]+[.]?[0-9]*$"); if (!IsNotEmpty(input)) { return false; } Match match = regUDecimal.Match(input); return match.Success;}
IsDecimal
/// <summary>/// Is a decimal number or not, including decimal./// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool IsDecimal(string input){ Regex regDecimal = new Regex("^[+-]?[0-9]+[.]?[0-9]*$"); //==> ^[+-]?\d+[.]?\d+$ if (!IsNotEmpty(input)) { return false; } Match match = regDecimal.Match(input); return match.Success;}
Chinese checking
/// <summary>/// check chinese is exist or not/// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool HasChinese(string input){ Regex regChinese = new Regex("[\u4e00-\u9fa5]"); if (!IsNotEmpty(input)) { return false; } Match match = regChinese.Match(input); return match.Success;}
Mail Address check
/// <summary>/// Is a floating-point numbers, may have + and -/// </summary>/// <param name="input">input string</param>/// <returns></returns>public static bool IsEmail(string input){ Regex regEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$"); if (!IsNotEmpty(input)) { return false; } Match match = regEmail.Match(input); return match.Success;}
MathRelative
ToSBC-转全角的函数
///转全角的函数(SBC case)//////任意字符串///全角字符串//////全角空格为12288,半角空格为32///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248/// public static string ToSBC(string input){ //半角转全角: char[] c = input.ToCharArray(); for (int i = 0; i < c.Length; i++) { if (c[i] == 32) { c[i] = (char)12288; continue; } if (c[i] < 127) c[i] = (char)(c[i] + 65248); } return new string(c);}
ToDBC-转半角的函数
///转半角的函数(DBC case)//////任意字符串///半角字符串//////全角空格为12288,半角空格为32///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248///public static string ToDBC(string input){ char[] c = input.ToCharArray(); for (int i = 0; i < c.Length; i++) { if (c[i] == 12288) { c[i] = (char)32; continue; } if (c[i] > 65280 && c[i] < 65375) c[i] = (char)(c[i] - 65248); } return new string(c);}
阅读全文
1 0
- 【c#】DataChecker工具类大全分享
- 日期工具类分享
- Android 分享工具类
- Jedis工具类分享
- ShareSdk分享工具类
- 分享文件上传工具类
- 分享一个工具类StringUtils
- android分享应用工具类
- 时间转化工具类分享
- ftp工具类的分享
- 银行卡验证工具类分享
- 分享一个SharedPreferences工具类
- 分享连接mysql工具类
- 分享一个工具类---SharedPreferences
- 工具类分享之《JsonUtil》
- 工具类分享之《IpUtil》
- [C++] 分享国外程序员的 C++开发资源大全
- 20160412 C/C++, C#常用开发工具大全
- mybatis:Invalid bound statement (not found):com.me.dao.UserDAO.insertRecord
- 大连理工大学软件学院C语言上机第五六章课后题
- KendoUI消息提示自定义
- 你们都说无人车时代将没有车祸!那这是怎么做到的? | 聚焦
- Access denied for user ''@'localhost' to database 'mysql'
- 【c#】DataChecker工具类大全分享
- 使用openwrt系统组件mesh(802.11s)网络
- 日本人口每年下降90万人?日本:用机器人补足空缺 | 行业
- 电视剧也能训练人工智能?爱丁堡大学对此进行了实验 | 研究
- ES6 React 组件引用本地图片问题
- 干货!手机APP进行测试的流程详解
- HDU Knight Moves
- javascript面向对象tab切换
- Deep Learning 第四课 CNN 第一周 作业2 Convolutional Neural Networks: Application