zoukankan      html  css  js  c++  java
  • c#字符类型判断

     1        /// <summary>
     2         /// 判断是否为空字符串
     3         /// </summary>
     4         /// <param name="p_Source">需要判断的字符串</param> 
     5         /// <remarks>全为空格的字符串(包括全角空格和半角)或字符串为 null 返回 true,否则返回false</remarks>
     6         /// <returns>true: 空字符串, false 非空字符串
     7         /// </returns>
     8         /// <seealso cref="IsNotNullString"/>
     9         public static bool IsNullString(string p_Source)
    10         {
    11             if (p_Source == null)
    12             {
    13                 return true;
    14             }
    15             p_Source = p_Source.Trim(' ', ' ');
    16             if (p_Source == String.Empty)
    17             {
    18                 return true;
    19             }
    20             return false;
    21         }
    22 
    23         /// <summary>
    24         /// 判断是否不为空字符串
    25         /// </summary>
    26         /// <param name="p_Source">需要判断的字符串</param> 
    27         /// <returns></returns>
    28         public static bool IsNotNullString(string p_Source)
    29         {
    30             return !IsNullString(p_Source);
    31         }
    32 
    33         /// <summary>
    34         /// 判断是否为空
    35         /// </summary>
    36         /// <param name="str">待检查数据。"",&nbsp;,null,&nbsp,undefined,Length == 0</param>
    37         /// <returns></returns>
    38         public static bool IsEmpty(string str)
    39         {
    40             if (string.IsNullOrEmpty(str) || str == "&nbsp;" || str == "&nbsp" || str.Length == 0 || str == "undefined") return true;
    41 
    42             return false;
    43         }
    44 
    45         /// <summary>
    46         /// 判断输入是否为日期类型
    47         /// </summary>
    48         /// <param name="strSrc">待检查数据 </param>
    49         /// <returns></returns>
    50         public static bool IsDate(string strSrc)
    51         {
    52             try
    53             {
    54                 DateTime d = DateTime.Parse(strSrc);
    55                 return true;
    56             }
    57             catch
    58             {
    59                 return false;
    60             }
    61         }
    62 
    63         /// <summary>
    64         /// 判断是否为数字
    65         /// </summary>
    66         /// <param name="strSrc">待检查数据</param>
    67         /// <returns></returns>
    68         public static bool IsNumeric(string strSrc)
    69         {
    70             if (strSrc != null && Regex.IsMatch(strSrc, @"^\d+$")) return true;
    71             return false;
    72         }
     1         /// <summary>
     2         /// 将字符串转换成 html 编码字符
     3         /// </summary>
     4         /// <param name="str"></param>
     5         /// <returns></returns>
     6         public static string HtmllEncode(string str)
     7         {
     8             return System.Web.HttpUtility.HtmlEncode(str);
     9         }
    10 
    11         /// <summary>
    12         /// 将 html 解码
    13         /// </summary> 
    14         /// <param name="str">要转换的字符串</param>
    15         /// <returns></returns>
    16         public static string HtmlDecode(string str)
    17         {
    18             return System.Web.HttpUtility.HtmlDecode(str);
    19         }
  • 相关阅读:
    【Elasticsearch 技术分享】—— ES 常用名词及结构
    【Elasticsearch 技术分享】—— Elasticsearch ?倒排索引?这都是什么?
    除了读写锁,JUC 下面还有个 StampedLock!还不过来了解一下么?
    小伙伴想写个 IDEA 插件么?这些 API 了解一下!
    部署Microsoft.ReportViewe
    关于TFS强制undo他人check out
    几段查看数据库表占用硬盘空间的tsql
    How to perform validation on sumbit only
    TFS 2012 Disable Multiple Check-out
    在Chrome Console中加载jQuery
  • 原文地址:https://www.cnblogs.com/chirifengye/p/2960924.html
Copyright © 2011-2022 走看看