我一直在試圖做出某種消息解析器,只獲取我發送的消息。例如,如果我有消息這樣的:消息解析器C#
Viktor Bale (11 aug. 2016 13:20:56):
Hi! How are you?
Not Viktor Bale (11 aug. 2016 13:20:56):
Hi! Good! And you?
Viktor Bale (11 aug. 2016 13:20:56):
Me too! And this message has
Two lines!
Not Viktor Bale (11 aug. 2016 13:20:56):
And this doesn't matter!
我需要寫Viktor Bale
這裏只是消息的代碼,那我tryed:
for (int i = 0; i < wordsList.Count; i++)
{
if (wordsList[i].StartsWith(defaultName))
{
while (!wordsList[i].StartsWith(dialName))
{
messages.Add(wordsList[i]);
}
}
}
wordsList
是我的郵件,從收到的名單txt文件並通過ReadAllLines
讀取上面的消息就是列表。
是我的名字,dialName
是我的對話者的名字。
但是,當我啓動它,我的應用程序簡單地凍結。我應該怎麼做?
你永遠不會在你的'while'循環增量'i'。所以如果它是真的,那麼這個循環會永遠運行。或..直到您無法在消息列表中添加更多項目 – MAV
您應該調試您的代碼。比如果你仍然無法找到你的無限循環[編輯]後與[mcve] –