C#获取数字字符串数值连续字符串
JieStr = "1,4,5,7,8,9,10,13,15,17,18,19,21,22,6,7,13"; JieStrArr = JieStr.Split(","); JieStrArr=JieStrArr.Distinct().ToArray(); //去重 Array.Sort(JieStrArr); //排序,从小到大 List<string> nstr = new List<string>(); int i1 = 0; int j1 = 0; while (i1 < JieStrArr.Length - 1) { j1 = i1; while (i1 < JieStrArr.Length - 1 && JieStrArr[i1].Ext_ToInt() == (JieStrArr[i1 + 1].Ext_ToInt() - 1)) { i1 = i1 + 1; } if (i1 != j1) { nstr.Add(JieStrArr[j1].Ext_IsDBNull() + '-' + JieStrArr[i1].Ext_IsDBNull()); } i1++; } //Ext_IsDBNull() 转字符串方法 Ext_ToInt() 转int类型
标签:JieStrArr,C#,ToInt,j1,数值,i1,Ext,字符串 From: https://www.cnblogs.com/ZhuMeng-Chao/p/18552687