温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:23blog v1.080709项目源代码
当前文件:
23blog/Common/Replace.cs[5K,2009-6-12 11:30:49],打开代码结构图
23blog/Common/Replace.cs[5K,2009-6-12 11:30:49],打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Text; 4
using System.Text.RegularExpressions; 5
6
namespace 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, "&", "&"); 28
strInput = Regex.Replace(strInput, "<", "<"); 29
strInput = Regex.Replace(strInput, ">", ">"); 30
strInput = Regex.Replace(strInput, "\'", "'"); 31
strInput = Regex.Replace(strInput, "\"", """); 32
strInput = Regex.Replace(strInput, "\\n", "<br>"); 33
strInput = Regex.Replace(strInput, "\\040", " "); 34
strInput = Regex.Replace(strInput, "\\t", " "); 35
return strInput; 36
} 37
38
//ubb替换 39
public static string ubbReplace(string strInput) 40
{ 41
strInput = Regex.Replace(strInput, "&", "&"); 42
strInput = Regex.Replace(strInput, "<", "<"); 43
strInput = Regex.Replace(strInput, ">", ">"); 44
strInput = Regex.Replace(strInput, "\'", "'"); 45
strInput = Regex.Replace(strInput, "\"", """); 46
strInput = Regex.Replace(strInput, "\\n", "<br>"); 47
strInput = Regex.Replace(strInput, "\\040", " "); 48
strInput = Regex.Replace(strInput, "\\t", " "); 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






}
}