我对流式阅读器有一个有趣的问题。
我的代码:
string file, text;
MatchCollection mcol;
private void btnGozat_Click(object sender, EventArgs e)
{
file = "c:/filelist.txt";
StreamReader sr = new StreamReader(@file,Encoding.Default);
text = sr.ReadToEnd();
Regex myreg = new Regex(@"[\d]{1,10}\n{1}(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})\s*([\w ığüşöçĞÜŞİÖÇâêî.!" + "\"" + @":'\-\\?\^,\s]*)(\n)$", RegexOptions.Multiline);
mcol = myreg.Matches(text);//<<<<<<<<<<<<<<<<<< care this row
for (int i = 0; i < mcol.Count; i++)
{
cbList.Items.Add(i.ToString());
}
}
当我尝试此代码 mcol.Count 为 0 并且任何项目未添加cbList.
但当我将文本变量写入richtextbox1 并将此行更改为“ mcol = myreg.Matches(richtextbox1.text);
”时,它正在工作。
private void btnGozat_Click(object sender, EventArgs e)
{
file = "c:/filelist.txt";
StreamReader sr = new StreamReader(@file, Encoding.Default);
icerik = sr.ReadToEnd();
richTextBox1.Text = icerik;//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Regex myreg = new Regex(@"[\d]{1,10}\n{1}(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})\s*([\w ığüşöçĞÜŞİÖÇâêî.!" + "\"" + @":'\-\\?\^,\s]*)(\n)$", RegexOptions.Multiline);
mcol = myreg.Matches(richTextBox1.Text);//<<<<<<<<<<<<<<<<<<<When i change this row it working
for (int i = 0; i < mcol.Count; i++)
{
cbList.Items.Add(i.ToString());
}
}
我的正则表达式正在工作我尝试。