her*_*ron 0 c# text file winforms
我想要实现的是加载文本文件,然后计算所有行:
我的代码看起来像这样:
string txtContent;
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtContent = File.ReadAllText(openFileDialog1.FileName);
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message, "Form1", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Run Code Online (Sandbox Code Playgroud)
我正在将txt文件内容读入txtContent字符串变量.但我不知道如何继续?
好吧,让我们做"提示",而不仅仅是给你代码......
File.ReadAllLines(.NET 2+)或File.ReadLines(.NET 4+)string.StartsWith和string.EndsWith确定字符串是否以特定方式开始或结束Count()方法来计算与谓词匹配的项目