求,用C#如何把1-4,6变成1,2,3,4,6?还有1-3,5,7-10这样类似的字符串呢?
4条回答 默认 最新
threenewbee 2023-03-15 11:20关注string s = "1-4,6"; string[] arr = s.split(','); List<int> list = new List<int>(); foreach (string i in arr) { if (i.Contains("-")) { for (int x = Convert.ToInt32(i.split('-')[0]); x <= Convert.ToInt32(i.split('-')[1]); x++) list.Add(x); } else list.Add(Convert.ToInt32(i)); }手写的,你参考下
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用