Asp.net源码专业站
首页->博客空间->23blog v1.080709项目源代码>>Common/Replace.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:23blog v1.080709项目源代码
当前文件:文件类型 23blog/Common/Replace.cs[5K,2009-6-12 11:30:49]打开代码结构图
普通视图
		            
1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Text.RegularExpressions; 5 6namespace Common 7{ 8 public class Replace 9 { 10 //截取指定数目的字符串 11 public static string OverflowReplace(string str, int num) 12 { 13 if (str.Length > num) 14 { 15 str = str.Substring(0, num); 16 return str + " . . ."; 17 } 18 else 19 { 20 return str; 21 } 22 } 23 24 //常规字符替换 25 public static string txtReplace(string strInput) 26 { 27 strInput = Regex.Replace(strInput, "&", "&amp;"); 28 strInput = Regex.Replace(strInput, "<", "&lt;"); 29 strInput = Regex.Replace(strInput, ">", "&gt;"); 30 strInput = Regex.Replace(strInput, "\'", "&#39;"); 31 strInput = Regex.Replace(strInput, "\"", "&#34;"); 32 strInput = Regex.Replace(strInput, "\\n", "<br>"); 33 strInput = Regex.Replace(strInput, "\\040", "&nbsp;"); 34 strInput = Regex.Replace(strInput, "\\t", "&nbsp;&nbsp;&nbsp;&nbsp;"); 35 return strInput; 36 } 37 38 //ubb替换 39 public static string ubbReplace(string strInput) 40 { 41 strInput = Regex.Replace(strInput, "&", "&amp;"); 42 strInput = Regex.Replace(strInput, "<", "&lt;"); 43 strInput = Regex.Replace(strInput, ">", "&gt;"); 44 strInput = Regex.Replace(strInput, "\'", "&#39;"); 45 strInput = Regex.Replace(strInput, "\"", "&#34;"); 46 strInput = Regex.Replace(strInput, "\\n", "<br>"); 47 strInput = Regex.Replace(strInput, "\\040", "&nbsp;"); 48 strInput = Regex.Replace(strInput, "\\t", "&nbsp;&nbsp;&nbsp;&nbsp;"); 49 strInput = Regex.Replace(strInput, "(?:\\[i\\])(?<body>[^\\[]+)(?:\\[/i\\])", "<i>${body}</i>", RegexOptions.IgnoreCase); 50 strInput = Regex.Replace(strInput, "(?:\\[b\\])(?<body>[^\\[]+)(?:\\[/b\\])", "<b>${body}</b>", RegexOptions.IgnoreCase); 51 strInput = Regex.Replace(strInput, "(?:\\[u\\])(?<body>[^\\[]+)(?:\\[/u\\])", "<u>${body}</u>", RegexOptions.IgnoreCase); 52 strInput = Regex.Replace(strInput, "(?:\\[url\\])(?<body>[^\\[]+)(?:\\[/url\\])", "<a href=\"${body}\" target=\"_blank\">${body}</a>", RegexOptions.IgnoreCase); 53 strInput = Regex.Replace(strInput, "(?:\\[email\\])(?<body>[^\\[]+)(?:\\[/email\\])", "<a href=\"mailto:${body}\">${body}</a>", RegexOptions.IgnoreCase); 54 strInput = Regex.Replace(strInput, "^(http://[A-Za-z0-9\\./=\\?%\\-&_~`@´:+!]+)", "<a href=\"$1\" target=\"_blank\">$1</a>", RegexOptions.IgnoreCase); 55 strInput = Regex.Replace(strInput, "(http://[A-Za-z0-9\\./=\\?%\\-&_~`@´:+!]+)$", "<a target=_blank href=$1>$1</a>", RegexOptions.IgnoreCase); 56 strInput = Regex.Replace(strInput, "[^>=\"](http://[A-Za-z0-9\\./=\\?%\\-&_~`@´:+!]+)", "<a target=_blank href=$1>$1</a>", RegexOptions.IgnoreCase); 57 return strInput; 58 } 59 } 60} 61
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:23blog v1.080709项目源代码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146