/// <summary> /// 对期刊装订库的年卷期进行组合 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string QueueString(string input) { var arr = new System.Collections.ArrayList(); var lines = input.Split(‘,‘).ToList(); lines = lines.OrderBy(x => int.Parse(x)).ToList(); int min, max, tmp = 1; max = min = int.Parse(lines[0]); foreach (var line in lines) { tmp = int.Parse(line); if ((tmp - max) > 1) { if (min == max) { arr.Add(string.Format("{0}", max)); max = min = tmp; } else { arr.Add(string.Format("{0}-{1}", min, max)); max = min = tmp; } } else { max = tmp; } } if ((tmp == min) || (tmp == max)) { arr.Add(string.Format("{0}-{1}", min, max)); } return string.Join(",", arr.ToArray()); }
时间: 2024-10-13 22:48:57