日期:2014-05-17 浏览次数:20492 次
public string FilterStr(string value, IList<string> filterList, bool isIgnoreCase, bool isReplaceAll) { string returnValue = value; string constFilter = "~!@##@!~"; for (int i = 0; i < filterList.Count; i++) { if (isIgnoreCase) { //不区分大小写 returnValue = System.Text.RegularExpressions.Regex.Replace(returnValue, filterList[i], constFilter + i.ToString(), System.Text.RegularExpressions.RegexOptions.IgnoreCase); } else { //区分大小写 returnValue = returnValue.Replace(filterList[i], constFilter + i.ToString()); } } string[] array; for (int i = 0; i < filterList.Count; i++) { if (isReplaceAll) { returnValue = returnValue.Replace(constFilter + i.ToString(), string.Format("<a href=\"http://www.21shipin.com\" target=\"_blank\" title=\"{0}\">{0} </a>", filterList[i])); } else { if (returnValue.Contains(constFilter + i.ToString())) { array = System.Text.RegularExpressions.Regex.Split(returnValue, constFilter + i.ToString(), System.Text.RegularExpressions.RegexOptions.IgnoreCase); for (int j = 0; j < array.Length; j++) { if (j == 0) { returnValue = string.Format("{0}<a href=\"http://www.21shipin.com\" target=\"_blank\" title=\"{1}\">{1} </a>", array[0], filterList[i]); } else { returnValue += string.Format("{0}{1}", array[j], (j == array.Length - 1 ? "" : filterList[i])); } } } } } return returnValue; }
------解决方案--------------------