过滤非法字符方法

2009年3月13日星期五

过滤非法字符方法

///
/// 检查字符串是否合法不合法替换
///

///
/// 替换后的字符串
public static string StrConvert(string strInput)
{
if ((strInput != null) && (strInput != ""))
{
//定义需要过滤的字符。
string[,] immit ={ { "'", "’" }, { "%20", " " }, { "%24", " " }, { "%27", " " }, { "%3a", " " }, { "%3b", " " }, { "%3c", " " }, { ";", ";" }, { ":", ":" }, { "%", "%" }, { "--", "--" }, { "*", "*" }, { "\\", "、、" } };
//遍历字符串,过滤掉需要过滤的字符
for (int i = 0; i < (immit.Length / 2); i++)
{
strInput = strInput.Replace(immit[i, 0], immit[i, 1]);
}
}
return strInput;//返回替换后的字符串
}

0 评论:

发表评论