日期:2014-05-17 浏览次数:20521 次
/// <summary> /// 过滤字符串中的html代码 /// </summary> /// <param name="Str"></param> /// <returns>返回过滤之后的字符串</returns> public static string LostHTML(string Str) { string Re_Str = ""; if (Str != null) { if (Str != string.Empty) { string Pattern = "<\\/*[^<>]*>"; Re_Str = Regex.Replace(Str, Pattern, ""); } } return (Re_Str.Replace("\\r\\n", "")).Replace("\\r", ""); } #region 截取字符串为指定长度 public static string CutStr(string sInString, int length) { if (sInString == null || sInString.Length == 0) return ""; int iCount = System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(sInString); if (iCount > length) { int iLength = 0; for (int i = 0; i < sInString.Length; i++) { int iCharLength = System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(new char[] { sInString[i] }); iLength += iCharLength; if (iLength == length) { sInString = sInString.Substring(0, i + 1) + "..."; break; } else if (iLength > length) { sInString = sInString.Substring(0, i) + "..."; break; } } } return sInString; } #endregion