Loading

过滤连续手机号码

string[] mobiles = new string[] { "13069230781", "13269230001", "15123439076", "13269230002", "13942190276", "13269230003", "13269230004", "13269230005", "13269230006", };

            Array.Sort(mobiles);

            //mobiles.Any(t => t.Substring(0, 3));

            List<string> mbs = new List<string>();
            for (int i = 0; i < mobiles.Length; i++)
            {
                mbs.Add(mobiles[i].Substring(0, 3));
            }

            var q =
            from p in mbs
            group p by p into g
            select new { 
                g.Key,
                count = g.Count(),
            };

            var res = System.Linq.Enumerable.Where(q, p => (p.count == (System.Linq.Enumerable.Max(q, t => t.count)))).ToList()[0].Key;

            //得到连续号码
            var reuslt = System.Linq.Enumerable.Where(mobiles, t => t.ToString().IndexOf(res.ToString()) > -1);

 

posted @ 2014-04-11 23:31  The Mechanic  阅读(166)  评论(0编辑  收藏  举报