我有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