Joh*_*ohn -4 c# asp.net-mvc streamreader asp.net-mvc-3
使用streamreader,如果行以'0'开头跳过该行???
string FileToProcess = System.IO.File.ReadAllText(@"up.FolderPath");
using (StreamReader sr = new StreamReader(FileToProcess))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.StartsWith("0"))
{
line.Skip();
// ????have to put a number line in here
// But i just want to skip the line it is on
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过不对其进行任何操作来跳过一行.最快的方式,使用continue;......
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.StartsWith("0"))
{
continue;
}
//process line logic
}
Run Code Online (Sandbox Code Playgroud)
使用continue将有效地while再次跳转到循环的开始,然后继续读取下一行,
这是基于我的理解,你想跳过开头的行 "0"