wzp
2023-03-02 374ce4ffd0c459bb4067e8d5765f972668aff9b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
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<string> srcList = new List<string>(Enumerable.Distinct<string>((IEnumerable<string>)srcText.Split(Enumerable.ToArray<char>((IEnumerable<char>)"\r\n;,|"), StringSplitOptions.RemoveEmptyEntries)));
            List<string> destList;
            for (destList = new List<string>(); SegmentHelper.Merge(srcList, destList); destList = new List<string>())
                srcList = destList;
            StringBuilder stringBuilder = new StringBuilder();
            foreach (string str in destList)
                stringBuilder.AppendLine(str);
            return stringBuilder.ToString();
        }
 
        private static bool Merge(List<string> srcList, List<string> 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<string>)srcList);
            return srcList.Count != destList.Count;
        }
 
        private static bool Remove(List<string> 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;
        }
    }
}