我有2個C#字符串列表,顯示已加入並離開特定遊戲的玩家。我試圖通過匹配兩個列表並且消除那些已經離開遊戲的人的條目來試圖確定誰還在遊戲中。請建議一個簡單而無痛的算法去做這件事。我當前的代碼如下所示C#字符串模式匹配
string input = inputTextBox.Text;
string[] lines = input.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.None);
List<string> filteredinput = new List<string>();
List<string> joinedlog = new List<string>();
List<string> leftlog = new List<string>();
for (int i = 0; i<lines.Length; i++)
{
if (lines[i].Contains("your game!"))
filteredinput.Add(lines[i]);
}
for (int i =0; i<filteredinput.Count; i++)
{
if (filteredinput[i].Contains("joined"))
joinedlog.Add(filteredinput[i]);
else if (filteredinput[i].Contains("left"))
leftlog.Add(filteredinput[i]);
}
下面是一些示例輸入:
{SheIsSoScrewed}[Ping:|] has joined your game!.
{AngeLa_Yoyo}[Ping:X] has joined your game!.
{SheIsSoScrewed} has left your game!(4).
您可以顯示一些示例輸入嗎? – 2011-06-04 08:48:05
確定我已經編輯它以顯示一些示例輸入 – paradox 2011-06-04 09:26:54