新生帖:一个用于字符串数组的智能排序类,用于相似度的对比!
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; } }