我试图这样做,以便我可以阅读"检查"之后出现的所有行,我尝试使用StreamReader或clicli,而且无法移动到下一行,始终读取同一行。
下面是一个提取的示例.txt文件,在文件中有许多注册表项。
TXTFile
Windows Registry Editor Version 5.00
//BEFORE MORE key
[HKEY_CURRENT_USER\SOFTWARE\Thingamahoochie\WinMerge\Settings-Bar1]
"BarID"=dword:00008033
"Visible"=dword:00000000
"XPos"=dword:fffffffe
"YPos"=dword:fffffffe
"Docking"=dword:00000001
"MRUDockID"=dword:00000000
"MRUDockLeftPos"=dword:00000000
"MRUDockTopPos"=dword:00000000
"MRUDockRightPos"=dword:0000070c
"MRUDockBottomPos"=dword:000000f5
"MRUFloatStyle"=dword:00002004
"MRUFloatXPos"=dword:80000000
"MRUFloatYPos"=dword:00000000
//MORE KEY AFTER
码
private void btnReplace_Click(object sender, EventArgs e)
{
string check = "[HKEY_CURRENT_USER\SOFTWARE\Thingamahoochie\WinMerge\Settings-Bar1]";
foreach (string line in File.ReadLines(_path))
{
if(line == check)
{
//need here read all line after "check"
}
}
}
答案 0 :(得分:2)
您可以使用布尔值来跟踪您是否在正确的位置:
这里我假设一个空行表示该部分的结尾。
bool readingTargetSection = false;
foreach (string line in File.ReadLines(_path))
{
if (readingTargetSection)
{
if (line.Trim() == "") {
// or just break out of the loop
readingTargetSection = false;
}
else {
// read the line
}
}
else if (line == check)
{
readingTargetSection = true;
}
}
答案 1 :(得分:1)
可以在这里使用LINQ。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="pagination" id="paginationUL">
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
</ul>