如果不要重复的id的话可以用hashset阿,自动过滤重复数据的

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.Text;using System.Text.RegularExpressions;namespace text
    {
        class test
        {
            private const string source = "267|266|265|264|263|262|261|260|259|258|257|256|255|254|253|252";
            private const string remove = "256|262";
            private const string add = "241|242|243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259";
            static void Main()
            {
                Hashtable htable = new Hashtable();
                if (getarr(source) != null && getarr(source).Length > 0)
                {
                    foreach (string s in getarr(source))
                    {
                        htable.Add(s, "value:" + s);
                    }
                }
                if (getarr(remove) != null && getarr(remove).Length > 0)
                {
                    foreach (string s in getarr(remove))
                    {
                        if (htable.ContainsKey(s))
                            htable.Remove(s);
                    }
                }
                if (getarr(add) != null && getarr(add).Length > 0)
                {
                    foreach (string s in getarr(add))
                    {
                        if (!htable.ContainsKey(s))
                            htable.Add(s, "value:" + s);
                    }
                }
                foreach (DictionaryEntry d in htable)
                {
                    Console.WriteLine(d.Key + " " + d.Value);
                }
                Console.ReadKey();
            }
            private static string[] getarr(string line)
            {
                if (line != null)
                {
                    return line.Trim().Split(new char[1] { '|' });
                }
                return null;
            }
        }
    }