日期:2014-05-17 浏览次数:20961 次
string[] array = { "1022012061513585300A21950001", "1032012061609083100A21950001", "1032012061609083800A21950001" }; SortedList<string, Tuple> slist = new SortedList<string, Tuple>(); foreach (var item in array) { string key = item.Substring(19, 6) + item.Substring(3, 12); string clock = item.Substring(0, 3); int second = int.Parse(item.Substring(15, 2)); Tuple tuple; if (slist.TryGetValue(key, out tuple)) { if (tuple.second < second) { tuple.clock = clock; tuple.second = second; } } else { tuple = new Tuple { clock = clock, second = second }; slist.Add(key, tuple); } } string[] result = new string[slist.Count]; for (int i = 0; i < slist.Count; i++) { string key = slist.Keys[i]; Tuple tuple = slist.Values[i]; result[i] = string.Concat(tuple.clock, key.Substring(6), tuple.second.ToString("D2"), "00", key.Substring(0, 6), "001"); }