用户名: 密   码:
   飞诺网 加入收藏
飞诺网 网站开发 VBScript ASP Asp.net Jsp php XML CGI-Perl 搜索引擎 ajax web技术
.net系列教程 .net实例 .Net技术文档

您当前的位置:飞诺网 >> .net >> .Net技术文档

新生帖:一个用于字符串数组的智能排序类,用于相似度的对比!

www.diybl.com    时间 : 2008-05-30  作者:佚名   编辑:本站 点击:   [ 评论 ]

        /// 
        /// 智能排序类
        /// 
        private class _Comparer : IComparer
        {
            public int Compare(string a, string b)
            {
                string x, y;
                if (a.Length >= b.Length)
                {
                    x = b;
                    y = a;
                }
                else
                {
                    x = a;
                    y = b;
                }

                int result = 0;

                if (x != y)
                {
                    List _x = new List(x.Length);

                    string s = x[0].ToString();
                    for (int i = 1; i < x.Length; i++)
                    {
                        if (Char.IsSeparator(x[i]))
                        {
                            _x.Add(s);
                            s = null;
                            i++;

                            if (i < x.Length)
                            {
                                s = x[i].ToString();
                            }
                        }
                        else
                        {
                            s += x[i].ToString();
                        }
                    }

                    if (s != null)
                    {
                        _x.Add(s);
                    }

                    foreach (string item in _x)
                    {
                        if (y.IndexOf(item) > -1 && ((float)(item.Length) / (float)(y.Length) > 0.5)) //0.5是相似度
                        {
                            return 0;
                        }
                    }

                    result = String.Compare(x, y);
               }

               return result;
            }
        }

 

如果图片或页面不能正常显示请点击这里
.Net技术文档推荐文章

文章评论