📄 common.cs
字号:
using System;
using System.Data;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using CRM.Model;
using CRM.IDAL;
namespace CRM.BLL
{
/// <summary>
/// 通用的方法类.包含通用的方法.
/// </summary>
public class Common
{
#region 过滤字符串
/// <summary>
/// 过滤字符串
/// </summary>
/// <param name="inputString">字符串</param>
/// <param name="maxLength">截取长度</param>
/// <returns></returns>
public static string CleanString(string inputString, int maxLength)
{
StringBuilder retVal = new StringBuilder();
// check incoming parameters for null or blank string
if ((inputString != null) && (inputString != String.Empty))
{
inputString = inputString.Trim();
//chop the string incase the client-side max length
//fields are bypassed to prevent buffer over-runs
if (inputString.Length > maxLength)
inputString = inputString.Substring(0, maxLength);
//convert some harmful symbols incase the regular
//expression validators are changed
for (int i = 0; i < inputString.Length; i++)
{
switch (inputString[i])
{
case '"':
retVal.Append(""");
break;
case '<':
retVal.Append("<");
break;
case '>':
retVal.Append(">");
break;
default:
retVal.Append(inputString[i]);
break;
}
}
// Replace single quotes with white space
retVal.Replace("'", " ");
}
return retVal.ToString();
}
#endregion
#region 检测字符串是否为空
/// <summary>
/// 检测字符串是否为空
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool CheckStrIsNull(params string[] str)
{
foreach(string s in str)
if(s ==null||s.Trim() == string.Empty)
return true;
return false;
}
#endregion
#region 加解密字符串
/// <summary>
/// 加解密字符串
/// </summary>
/// <param name="String">字符串</param>
/// <returns></returns>
public static string Encrypt(string str)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(str);
Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -