它计数 23 但有 30 行是"占位符:占位符"............
using (StreamReader Reader = new StreamReader(File.Open(AccountsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
string line;
while ((line = Reader.ReadLine()) != null)
{
if (line == "Placeholder:Placeholder")
{
int count = line.Count();
}
}
}
声明一个变量来存储计数,并在每次行与模式字符串匹配时递增计数。
using (StreamReader Reader = new StreamReader(File.Open(AccountsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
string line;
int count = 0;
while ((line = Reader.ReadLine()) != null)
{
if (line == "Placeholder:Placeholder")
{
count++;
}
}
}