文本解析挂起
您好,我有以下代码:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
String line;
line = sr.ReadLine();
while ((line != null))
{
if (line.StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
当我使用此功能时,应用程序似乎只是挂在那里而不执行任何操作。这里的 while 循环有问题吗?
编辑1:
我现在使用的代码有错误:“System.IO.StreamReader”不包含“Readline”的定义,并且没有扩展方法“Readline”接受类型“System.IO.StreamReader”的第一个参数发现
代码:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
while (sr.Peek() >= 0)
{
if (sr.Readline().StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
在这一行发现错误:
if (sr.Readline().StartsWith("Exec_mail"))
hi i have the following code:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
String line;
line = sr.ReadLine();
while ((line != null))
{
if (line.StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
When i use this function, it seems that the application just hangs there without doing anything. Is this something wrong with the while loop here?
EDIT 1:
the code i am using now has the error: 'System.IO.StreamReader' does not contain a definition for 'Readline' and no extension method 'Readline' accepting a first argument of type 'System.IO.StreamReader' could be found
code:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
while (sr.Peek() >= 0)
{
if (sr.Readline().StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
error is found in this line:
if (sr.Readline().StartsWith("Exec_mail"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 StreamReader.Peek () 来确定文件结尾:
编辑:
我使用位于 D:\aa.txt 的示例文本文件运行代码,其中包含 4 行文本:
执行邮件
abcd
执行邮件
哎呀
Exec_mail
使用此代码:
并且它显示了 3 次是。
Use StreamReader.Peek() to determine the end of file:
EDIT:
I ran the code with a sample text file located at D:\aa.txt with 4 lines of text in it as:
Exec_mail
abcd
Exec_mail
efgh
Exec_mail
using this code:
And it showed yes three times.