它有23个,但有30行是&#34;占位符:占位符&#34; ........................... ................................................. < / p>
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();
}
}
}
答案 0 :(得分:0)
声明一个变量来存储计数,并在每次一行与模式字符串匹配时递增它。
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++;
}
}
}