0

可能重复:
将列表转换为数字范围字符串

假设我有以下代码:

List<int> ints = new List<int>();
//myValues are of type List<string>
for(int i=0; i<myValues.count; i++)
{
  string myVal = myValues[i];
  if (myVal=="testing")
  {
    ints.Add(i+1);
  }
}

String.Join (", ", ints);

这将是这样的:

1,2,3,6,7,8,9,10,14

我正在寻找一种方法来显示这样的值:

1-3, 6-10, 14

有什么建议么?

4

0 回答 0