using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Common { public class SegmentHelper { public static string Filrate(string srcText) { if (string.IsNullOrEmpty(srcText)) return string.Empty; List srcList = new List(Enumerable.Distinct((IEnumerable)srcText.Split(Enumerable.ToArray((IEnumerable)"\r\n;,|"), StringSplitOptions.RemoveEmptyEntries))); List destList; for (destList = new List(); SegmentHelper.Merge(srcList, destList); destList = new List()) srcList = destList; StringBuilder stringBuilder = new StringBuilder(); foreach (string str in destList) stringBuilder.AppendLine(str); return stringBuilder.ToString(); } private static bool Merge(List srcList, List destList) { foreach (string str in srcList.ToArray()) { if (str.Length > 5) { string s = str.Substring(0, str.Length - 1); if (SegmentHelper.Remove(srcList, s)) destList.Add(s); } } destList.AddRange((IEnumerable)srcList); return srcList.Count != destList.Count; } private static bool Remove(List srcList, string s) { for (int index = 0; index < 10; ++index) { if (!srcList.Contains(s + (object)index)) return false; } for (int index = 0; index < 10; ++index) srcList.Remove(s + (object)index); return true; } } }