List<int> ids = ExtractIds("United Kingdom (656) - Aberdeen (7707)");
上記のリストは、括弧内から値を削除する以下のメソッドによって入力する必要があります。
match.Value を文字列として使用し、それを List< string > に割り当てると、問題なく動作するようです。しかし、それを整数に変換しようとすると、「入力文字列の形式が正しくありませんでした」というエラーが表示されます。
私は何を間違っていますか?
public List<int> ExtractIds(string str)
{
MatchCollection matchCollection = Regex.Matches(str, @"\((.*?)\)");
List<int> ExtractedIds = new List<int>();
foreach (Match match in matchCollection)
{
int theid = int.Parse(match.Value);
ExtractedIds.Add(theid);
}
return ExtractedIds;
}