System.IO.StreamReader file = new System.IO.StreamReader(@"data.txt");
List<String> Spec= new List<String>();
while (file.EndOfStream != true)
{
string s = file.ReadLine();
Match m = Regex.Match(s, "Spec\\s");
if (m.Success)
{
int a = Convert.ToInt16(s.Length);
a = a - 5;
string part = s.Substring(5, a);
Spec.Add(part);
}
}
我正在尝试获取包含单词“Spec”和空格字符的所有行,但是当我运行该程序时出现错误。
异常详情如下:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
任何人都可以帮助我找出原因吗?
文本文件:
ID 560
Spec This ... bla bla
blah...
blah...
bla bla
bla
Category Other
Price $259.95
ID 561
Spec more blah blah...
blah...
blah...
bla bla
bla
Category Other
Price $229.95