使用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
}
}
}
答案 0 :(得分:7)
您可以通过不对其进行任何操作来跳过一行。最快的方法是使用continue;
...
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.StartsWith("0"))
{
continue;
}
//process line logic
}
使用continue
将有效地再次跳转到while
循环的开头,然后继续阅读下一行,
这是基于我的理解,您希望跳过以"0"
答案 1 :(得分:1)
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"))
{
continue;
}
else{
//Do stuff here
}
}
}
答案 2 :(得分:-3)
仅当行不以'0'
开头时才对该行执行某些操作