C#のRegex.Matchesメソッドを用いて文字列から正規表現を使い、
特定の文字列を検索してint型で保存するプログラムを作っています。
以下のプログラムを作成したのですが、ループ後の部分で
System.Text.RegularExpressions.Match から intへ変換することはできません
とエラーになってしまいます。
これを解決する方法を教えていただきたいです。
C#
1using System; 2using System.Text.RegularExpressions; 3 4class Program 5{ 6 static void Main() 7 { 8 string s = "[6,32] [4,5] [12,13]"; 9 10 Regex rx1 = new Regex("[0-9]{1,2}"); 11 12 if (rx1.IsMatch(s)) 13 { 14 MatchCollection matches = rx1.Matches(s); 15 for (int i = 0; i < 6; i++) 16 { 17 Console.WriteLine(matches[i]); 18 } 19 20 //int a = Int32.Parse(matches[1]); // この部分でエラー 21 //Console.WriteLine(a); 22 } 23 } 24} 25
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。