C# ip的排序方法

     private List<string> IpOrderBy(List<string> ips)
        {
            List<string> ipList = new List<string>();

            if (ips != null && ips.Count > 0)
            {
                for (int i = 0; i < ips.Count; i++)
                {
                    var ip = ips[i];
                    ip = Regex.Replace(ip, "(\\d+)", "00$1");
                    ip = Regex.Replace(ip, "0*(\\d{3})", "$1");
                    ips[i] = ip;
                }
                var ts = new SortedSet<string>(ips);

                foreach (var ip in ts)
                    ipList.Add(Regex.Replace(ip, "0*(\\d+)", "$1"));
            }
            return ipList;
        }

  

posted @ 2020-12-23 10:41  石shi  阅读(359)  评论(0编辑  收藏  举报