gpt4 book ai didi

c# - StringReader 不是 "exiting"/中断

转载 作者:太空宇宙 更新时间:2023-11-03 19:40:49 26 4
gpt4 key购买 nike

我在使用以下代码时遇到问题......当我运行它时,代码永远不会退出。我已经尝试调试了大约一个小时,但我完全不知道问题出在哪里。输出调试();本质上类似于 Console.WriteLine();

//Iterate through all lines to find sections
using (StringReader lineReader = new StringReader(Program))
{
int i = 0;
string line = string.Empty;
while (line != null)
{
line = lineReader.ReadLine();
if (line != string.Empty)
{
//If the program is exiting (doExit == true), then break the lööp bröther
if (doExit)
break;

//Iterate through all characters in the line
foreach (char Character in line)
{
i++;
OutputDebug(i.ToString());
if (isOnSameLineAsSectionStart)
{
sectionName += Character;
}
else if (Character == ':' && sectionName == string.Empty)
{
isOnSameLineAsSectionStart = true;
}
else if (Character == ':' && !isOnSameLineAsSectionStart && sectionName != string.Empty)
{
OutputDebug("End of section \"" + sectionName + "\" found");
OutputDebug(linesInSection.Count() + " lines found total in " + sectionName + "\" during section search");
try
{
sections.Add(sectionName, linesInSection);
}
catch (Exception)
{
OutputError("Two/Multiple sections with the same names exist. Ignoring the latest section with the same name");
}
linesInSection = new List<string>();
sectionName = string.Empty;
isOnSameLineAsSectionStart = true;
}
}
if (!isOnSameLineAsSectionStart && sectionName != string.Empty)
{
linesInSection.Add(line);
}
if (isOnSameLineAsSectionStart && sectionName != string.Empty)
{
OutputDebug("Start of section \"" + sectionName + "\" found");
}
if (isOnSameLineAsSectionStart == true)
{
isOnSameLineAsSectionStart = false;
}
}
lineReader.Close();
OutputDebug("In StringReader!" + i);
}

提前致谢!

最佳答案

您可以使用以下 while 方法:

while ((line = reader.ReadLine()) != null)
{
foreach (char Character in line)
{
i++;
OutputDebug(i.ToString());
}
}

关于c# - StringReader 不是 "exiting"/中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53785763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com