私は、テキストを含む大規模な文字列を持っている:私はこの文字列の値に基づいて、それのアイテムをリストボックスを作成しようとしています大きな文字列からリストボックス項目を作成
"value 1
value 2
value 3
etc..." //over 100 values
を。
私は、エラーを停止した範囲の例外のうちの引数を得ていたように私は、tryキャッチを使用しますが、私は、リストボックス内のすべての項目を見ることができません:P
string value = "";
int currentIndexPos = 0;
foreach (System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(listStr, "\r\n?"))
{
try
{
value = formatted.Substring(currentIndexPos, m.Index - 1); // -1 so the matched value isn't used.
listBox1.Items.Add(value);
currentIndexPos = m.Index + 1;
}
catch
{
//argument out of range exception
//Index and length must refer to a location within the string. Parameter name: length
}
}
m.Indexの値を調べましたか? – kaj
最初のマッチでは、mのインデックスは0ですか?したがって、m.Index - 1は引数を範囲外のエラーにしますか? –