110,580
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
string sRegSplit = @"\[(?<time>\d+-\d+-\d+ \d+:\d+:\d+)\] logtype:\[(?<logtype>\w+)\] company:\[(?<company>\w+)\] uid\[(?<uid>\d+)\]";
System.Text.RegularExpressions.Regex reSplit =
new System.Text.RegularExpressions.Regex(sRegSplit, System.Text.RegularExpressions.RegexOptions.Compiled);
Dictionary<string, Information> dictT = new Dictionary<string, Information>();
List<Information> lstT = new List<Information>();
using (System.IO.StreamReader srT = new System.IO.StreamReader("数据文件", Encoding.Default))
{
while (!srT.EndOfStream)
{
Information infor = new Information();
System.Text.RegularExpressions.Match match = reSplit.Match(srT.ReadLine());
infor.time = match.Groups["time"].Value;
infor.logtype = match.Groups["logtype"].Value;
infor.company = match.Groups["company"].Value;
infor.uid = match.Groups["uid"].Value;
lstT.Add(infor);//全要
if (!dictT.ContainsKey(infor.company))//去除掉不需要的
dictT.Add(infor.company, infor);
}
}
lstT.Sort(CompareInformation);
}
private static int CompareInformation(Information I1, Information I2)
{
//下面二句设成要比较的字段
string x = I1.company;
string y = I2.company;
int ret = 0;
if (x == null)
{
if (y != null)
ret = -1;
}
else
{
if (y == null)
{
ret = 1;
}
else
{
ret = x.CompareTo(y);
}
}
return ret;
}
struct Information
{
public string time;
public string logtype;
public string company;
public string uid;
}
private void Form1_Load(object sender, EventArgs e)
{
string sRegSplit = @"\[(?<time>\d+-\d+-\d+ \d+:\d+:\d+)\] logtype:\[(?<logtype>\w+)\] company:\[(?<company>\w+)\] uid\[(?<uid>\d+)\]";
System.Text.RegularExpressions.Regex reSplit =
new System.Text.RegularExpressions.Regex(sRegSplit, System.Text.RegularExpressions.RegexOptions.Compiled);
Dictionary<string, Information> dictT = new Dictionary<string, Information>();
List<Information> lstT = new List<Information>();
using (System.IO.StreamReader srT = new System.IO.StreamReader("数据文件", Encoding.Default))
{
while (!srT.EndOfStream)
{
Information infor = new Information();
System.Text.RegularExpressions.Match match = reSplit.Match(srT.ReadLine);
infor.time = match.Groups["time"].Value;
infor.logtype = match.Groups["logtype"].Value;
infor.company = match.Groups["company"].Value;
infor.uid = match.Groups["uid"].Value;
lstT.Add(infor);
if (!dictT.ContainsKey(infor.company))
dictT.Add(infor.company, infor);
}
}
lstT.Sort(CompareInformation);
}
private static int CompareInformation(Information I1, Information I2)
{
string x = I1;
string y = I2;
if (x == null)
{
if (y == null)
{
return 0;
}
else
{
return -1;
}
}
else
{
if (y == null)
{
return 1;
}
else
{
int retval = x.CompareTo(y);
}
}
}
struct Information
{
public string time;
public string logtype;
public string company;
public string uid;
}