温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NETCMSv1.5(Build0509)完整源码版
当前文件路径:NetCMSv15/NetCMS.Common/Input.cs

1//====================================================== 2
//== (c)2008 aspxcms inc by NeTCMS v1.0 == 3
//== Forum:bbs.aspxcms.com == 4
//== Website:www.aspxcms.com == 5
//====================================================== 6
using System; 7
using System.Text; 8
using System.Text.RegularExpressions; 9
using System.Web; 10
using System.Security.Cryptography; 11
12
namespace NetCMS.Common 13
{ 14
public class Input 15
{ 16
/// <summary> 17
/// 检测是否整数型数据 18
/// </summary> 19
/// <param name="Num">待检查数据</param> 20
/// <returns></returns> 21
public static bool IsInteger(string Input) 22
{ 23
if (Input == null) 24
{ 25
return false; 26
} 27
else 28
{ 29
return IsInteger(Input, true); 30
} 31
} 32
33
/// <summary> 34
/// 是否全是正整数 35
/// </summary> 36
/// <param name="Input"></param> 37
/// <returns></returns> 38
public static bool IsInteger(string Input, bool Plus) 39
{ 40
if (Input == null) 41
{ 42
return false; 43
} 44
else 45
{ 46
string pattern = "^-?[0-9]+$"; 47
if (Plus) 48
pattern = "^[0-9]+$"; 49
if (Regex.Match(Input, pattern, RegexOptions.Compiled).Success) 50
{ 51
return true; 52
} 53
else 54
{ 55
return false; 56
} 57
} 58
} 59
60
/// <summary> 61
/// 判断输入是否为日期类型 62
/// </summary> 63
/// <param name="s">待检查数据</param> 64
/// <returns></returns> 65
public static bool IsDate(string s) 66
{ 67
try 68
{ 69
DateTime d = DateTime.Parse(s); 70
return true; 71
} 72
catch 73
{ 74
return false; 75
} 76
} 77
78
79
/// <summary> 80
/// 过滤字符串中的html代码 81
/// </summary> 82
/// <param name="Str"></param> 83
/// <returns>返回过滤之后的字符串</returns> 84
public static string LostHTML(string Str) 85
{ 86
string Re_Str = ""; 87
if (Str != null) 88
{ 89
if (Str != string.Empty) 90
{ 91
string Pattern = "<\\/*[^<>]*>"; 92
Re_Str = Regex.Replace(Str, Pattern, ""); 93
} 94
} 95
return (Re_Str.Replace("\\r\\n", "")).Replace("\\r", ""); 96
} 97
98
public static string LostPage(string Str) 99
{ 100
string Re_Str = ""; 101
if (Str != null) 102
{ 103
if (Str != string.Empty) 104
{ 105
string Pattern = "\\[NT:PAGE\\/*[^<>]*\\$\\]"; 106
Re_Str = Regex.Replace(Str, Pattern, ""); 107
} 108
} 109
return Re_Str; 110
} 111
112
public static string LostVoteStr(string Str) 113
{ 114
string Re_Str = ""; 115
if (Str != null) 116
{ 117
if (Str != string.Empty) 118
{ 119
string Pattern = "\\[NT:unLoop\\/*[^<>]*\\[\\/NT:unLoop\\]"; 120
Re_Str = Regex.Replace(Str, Pattern, ""); 121
} 122
} 123
return Re_Str; 124
} 125
126
/// <summary> 127
/// 根据新闻标题的属性设置返回设置后的标题 128
/// </summary> 129
/// <param name="Title">标题</param> 130
/// <param name="TitleColor">标题颜色</param> 131
/// <param name="IsB">是否粗体</param> 132
/// <param name="IsI">是否斜体</param> 133
/// <param name="TitleNum">返回标题字数</param> 134
/// <returns>返回设置后的标题</returns> 135
public static string GetColorTitleSubStr(string Title, string TitleColor, int IsB, int IsI, int TitleNum) 136
{ 137
string Return_title = ""; 138
string FormatTitle = LostHTML(Title); 139
if (FormatTitle != null && FormatTitle != string.Empty) 140
{ 141
FormatTitle = GetSubString(FormatTitle, TitleNum); 142
if (IsB == 1) 143
{ 144
FormatTitle = "<b>" + FormatTitle + "</b>"; 145
} 146
if (IsI == 1) 147
{ 148
FormatTitle = "<i>" + FormatTitle + "</i>"; 149
} 150
if (TitleColor != null && TitleColor != string.Empty) 151
{ 152
FormatTitle = "<font style=\"color:" + TitleColor + ";\">" + FormatTitle + "</font>"; 153
} 154
Return_title = FormatTitle; 155
} 156
return Return_title; 157
} 158
159
160
/// <summary> 161
/// 截取字符串函数 162
/// </summary> 163
/// <param name="Str">所要截取的字符串</param> 164
/// <param name="Num">截取字符串的长度</param> 165
/// <returns></returns> 166
public static string GetSubString(string Str, int Num) 167
{ 168
if (Str == null || Str == "") 169
return ""; 170
string outstr = ""; 171
int n = 0; 172
foreach (char ch in Str) 173
{ 174
n += System.Text.Encoding.Default.GetByteCount(ch.ToString()); 175
if (n > Num) 176
break; 177
else 178
outstr += ch; 179
} 180
return outstr; 181
} 182
/// <summary> 183
/// 截取字符串函数 184
/// </summary> 185
/// <param name="Str">所要截取的字符串</param> 186
/// <param name="Num">截取字符串的长度</param> 187
/// <param name="Num">截取字符串后省略部分的字符串</param> 188
/// <returns></returns> 189
public static string GetSubString(string Str, int Num, string LastStr) 190
{ 191
return (Str.Length > Num) ? Str.Substring(0, Num) + LastStr : Str; 192
} 193
194
/// <summary> 195
/// 验证字符串是否是图片路径 196
/// </summary> 197
/// <param name="Input">待检测的字符串</param> 198
/// <returns>返回true 或 false</returns> 199
public static bool IsImgString(string Input) 200
{ 201
return IsImgString(Input, "/{@dirfile}/"); 202
} 203
204
public static bool IsImgString(string Input, string checkStr) 205
{ 206
bool re_Val = false; 207
if (Input != string.Empty) 208
{ 209
string s_input = Input.ToLower(); 210
if (s_input.IndexOf(checkStr.ToLower()) != -1 && s_input.IndexOf(".") != -1) 211
{ 212
string Ex_Name = s_input.Substring(s_input.LastIndexOf(".") + 1).ToString().ToLower(); 213
if (Ex_Name == "jpg" || Ex_Name == "gif" || Ex_Name == "bmp" || Ex_Name == "png") 214
{ 215
re_Val = true; 216
} 217
} 218
} 219
return re_Val; 220
} 221
222
223
/// <summary> 224
/// 将字符转化为HTML编码 225
/// </summary> 226
/// <param name="str">待处理的字符串</param> 227
/// <returns></returns> 228
public static string HtmlEncode(string Input) 229
{ 230
return HttpContext.Current.Server.HtmlEncode(Input); 231
} 232
233
/// <summary> 234
/// 235
/// </summary> 236
/// <param name="Input"></param> 237
/// <returns></returns> 238
public static string HtmlDecode(string Input) 239
{ 240
return HttpContext.Current.Server.HtmlDecode(Input); 241
} 242
243
/// <summary> 244
/// URL地址编码 245
/// </summary> 246
/// <param name="Input"></param> 247
/// <returns></returns> 248
public static string URLEncode(string Input) 249
{ 250
return HttpContext.Current.Server.UrlEncode(Input); 251
} 252
253
/// <summary> 254
/// URL地址解码 255
/// </summary> 256
/// <param name="Input"></param> 257
///




