重複の可能性:
リストを数値範囲文字列に変換する
次のコードがあるとします。
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
助言がありますか?