usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Text.RegularExpressions;usingSystem.IO;namespaceQQGroupCount
{publicpartialclassQQGroupCounter : Form
{publicQQGroupCounter()
{
InitializeComponent();
}privatevoidbtnBroswer_Click(objectsender, EventArgs e)
{
openFileDialog1.ShowDialog();
}privatevoidopenFileDialog1_FileOk(objectsender, CancelEventArgs e)
{
txtFilePath.Text=openFileDialog1.FileName;
btnCount.Focus();
}privatevoidbtnCount_Click(objectsender, EventArgs e)
{
StreamReader sr=newStreamReader(txtFilePath.Text);
CountingContent(sr.ReadToEnd());
sr.Dispose();
}voidCountingContent(stringcontent)
{stringpattern=@"\d{4}[\-|/]\d{1,2}[\-|/]\d{1,2} \d{1,2}:\d{1,2}:\d{1,2} (.[^\(\)\]*)(\(\d+\)|\<.>]*\>)";
MatchCollection mc=Regex.Matches(content, pattern, RegexOptions.Multiline);
Listlist=newList();stringqq, name;foreach(Match minmc)
{
qq=m.Groups[2].Value.Replace('(','\0').Replace(')','\0').Replace('','\0');
name=m.Groups[1].Value;
QQUser user=list.Find(u=>u.QQ==qq);if(user==null)
user=list.Find(u=>u.NickName==name);if(user==null)
{
user=newQQUser();
user.QQ=qq;
user.NickName=name;
user.Count=1;
list.Add(user);
}else{
user.Count++;
user.NickName=name;
}
}
list=list.OrderByDescending(u=>u.Count).ToList();inti=0;foreach(QQUser userinlist)
{
i++;
user.Rank=i;
}
dataGridView1.DataSource=list;
}
}publicclassQQUser
{publicintRank {get;set; }publicstringNickName {get;set; }publicstringQQ {get;set; }publicintCount {get;set; }
}
}