这篇文章给大家介绍asp.net常用函数收藏,主要包括 得到站点用户IP,去除字符串最后一个','号、去除字符串第一个'/'号等,感兴趣的朋友跟随小编一起看看吧
具体代码如下所示:
////// 得到站点用户IP /// ///public static string getUserIP() { return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); } /// /// 去除字符串最后一个','号 /// /// :要做处理的字符串 ///返回已处理的字符串 public static string Lost(string chr) { if (chr == null || chr == string.Empty) { return ""; } else { chr = chr.Remove(chr.LastIndexOf(",")); return chr; } } ////// 去除字符串第一个'/'号 /// /// 要做处理的字符串 ///返回已处理的字符串 public static string lostfirst(string chr) { string flg = ""; if (chr != string.Empty || chr != null) { if (chr.Substring(0, 1) == "/") flg = chr.Replace(chr.Substring(0, 1), ""); else flg = chr; } return flg; } ////// 替换html中的特殊字符 /// /// 需要进行替换的文本。 ///替换完的文本。 public static string HtmlEncode(string theString) { theString = theString.Replace(">", ">"); theString = theString.Replace("<", "<"); theString = theString.Replace(" ", " "); theString = theString.Replace(" ", " "); theString = theString.Replace("\"", """); theString = theString.Replace("\'", "'"); theString = theString.Replace("\n", "
"); return theString; } ////// 恢复html中的特殊字符 /// /// 需要恢复的文本。 ///恢复好的文本。 public static string HtmlDiscode(string theString) { theString = theString.Replace(">", ">"); theString = theString.Replace("<", "<"); theString = theString.Replace(" ", " "); theString = theString.Replace(" ", " "); theString = theString.Replace(""", "\""); theString = theString.Replace("'", "\'"); theString = theString.Replace("
", "\n"); return theString; } ////// 生成随机数字 /// /// 生成长度 ///public static string Number(int Length) { return Number(Length, false); } /// /// 生成随机数字 /// /// 生成长度 /// 是否要在生成前将当前线程阻止以避免重复 ///public static string Number(int Length, bool Sleep) { if (Sleep) System.Threading.Thread.Sleep(3); string result = ""; System.Random random = new Random(); for (int i = 0; i 12下一页阅读全文
相关文章
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程
如果在 Microsoft .NET Framework 2.0 上构建的基于 Microsoft ASP.NET 的应用程序中引发未处理的异常,该应用程序将会意外退出。如果出现这个问题,不会在应用程序日志中记录了解此问题所必需的异常信息。2009-11-11如何在ASP.NET Core中使用HttpClientFactory
这篇文章主要介绍了如何在ASP.NET Core中使用HttpClientFactory,帮助大家更好的理解和学习使用.net技术,感兴趣的朋友可以了解下2021-04-04asp.net+Ligerui实现grid导出Excel和Word的方法
这篇文章主要介绍了asp.net+Ligerui实现grid导出Excel和Word的方法,实例分析了asp.net结合jQuery的Ligerui插件操作excel和word文件的技巧,需要的朋友可以参考下2016-04-04
最新评论