zoukankan      html  css  js  c++  java
  • 字符串扩展方法 itprobie

    字符串扩展方法

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 
     6 using System.Text;
     7 
     8 public static class StringExtend
     9 {
    10     public static DateTime ToDatetime(this string str)
    11     {
    12         if (string.IsNullOrEmpty(str))
    13             return DateTime.MinValue;
    14         else
    15             return Convert.ToDateTime(str);
    16     }
    17 
    18     public static DateTime? ToNullableDatetime(this string str)
    19     {
    20         if (string.IsNullOrEmpty(str))
    21             return null;
    22         else
    23             return Convert.ToDateTime(str);
    24     }
    25 
    26     public static int ToInt32(this string str)
    27     {
    28         if (string.IsNullOrEmpty(str))
    29             return int.MinValue;
    30         else
    31             return Convert.ToInt16(str);
    32     }
    33 
    34     public static int? ToInt32(this string str)
    35     {
    36         if (string.IsNullOrEmpty(str))
    37             return null;
    38         else
    39             return Convert.ToInt16(str);
    40     }
    41     public static string HtmlDecode(this string str)
    42     {
    43         StringBuilder sb = new StringBuilder(str);
    44         sb.Replace("<br />", "\n");
    45         sb.Replace("\r", "");
    46         sb.Replace("&nbsp;&nbsp;", "\t");
    47         sb.Replace("&nbsp;", " ");
    48         sb.Replace("&#39;", "\'");
    49         sb.Replace("&quot;", "\"");
    50         sb.Replace("&gt;", ">");
    51         sb.Replace("&lt;", "<");
    52         sb.Replace("&amp;", "&");
    53         return sb.ToString();
    54     }
    55 
    56     public static string HtmlEncode(this string str)
    57     {
    58         StringBuilder sb = new StringBuilder(str);
    59         sb.Replace("&", "&amp;");
    60         sb.Replace("<", "&lt;");
    61         sb.Replace(">", "&gt;");
    62         sb.Replace("\"", "&quot;");
    63         sb.Replace("\'", "&#39;");
    64         sb.Replace(" ", "&nbsp;");
    65         sb.Replace("\t", "&nbsp;&nbsp;");
    66         sb.Replace("\r", "");
    67         sb.Replace("\n", "<br />");
    68         return sb.ToString();
    69     }
    70 }
  • 相关阅读:
    用Python实现QQ找茬游戏外挂工具
    Python常用模块
    将Qt 动态链接生成的exe及依赖dll打包方法
    Qt之VLFeat SLIC超像素分割(Cpp版)
    android studio下的NDK开发详解(一)
    条件注释判断浏览器版本<!--[if lt IE 9]>
    人脸识别中的八大难题,何时能解
    人脸识别简史与近期进展
    openCV之头文件分析
    看(学习)代码流程
  • 原文地址:https://www.cnblogs.com/guohu/p/2700940.html
Copyright © 2011-2022 走看看