标签:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace samdiaToExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOrderFilter_Click(object sender, EventArgs e)
{
String samdiaTxtIn = samdiaTxtInbox.Text;
//1.提取一发一收命令的正则表达式,只提取数据流22和62命令
Regex reg0 = new Regex(@">.* 22.*\n<.* 62.*");
string pattern = @">.* 22.*\n<.* 62.*";
//返回正则表达式的集合
MatchCollection mc = Regex.Matches(samdiaTxtIn, pattern);
int count = mc.Count;
//2.把提取出的基本命令整理后放到列表集合
List<string> orderListNoDelSame = new List<string>();
//3.删除秒后面的时间和命令间隔时间,并添加CANID:
for (int i=0; i < mc.Count; i++)
{
Regex reg1 = new Regex(@"\..* ");
string input = reg1.Replace(mc[i].ToString(), " CANID:").ToString();
orderListNoDelSame.Add(input);
}
////4.删除同一秒相同的命令
//List<string> orderList = new List<string>();
////orderList.Add(orderListNoDelSame[0]);
//for (int i = 0; i < orderListNoDelSame.Count; i++)
//{
// string sameSendTime = @">.*<";
// Match m = Regex.Match(orderListNoDelSame[i].ToString(), sameSendTime, RegexOptions.Singleline);
// string currentOrderStr = m.ToString();
// string orderListStr = string.Join("", orderList.ToArray());
// if (orderListStr.IndexOf(currentOrderStr) == -1)
// {
// orderList.Add(orderListNoDelSame[i]);
// }
//}
//join效率太低
string s = string.Join("", orderListNoDelSame.ToArray());
samdiaTxtOutBox.Text = s;
//samdiaTxtOutBox.Text = "1";
}
}
}
标签:
原文地址:http://www.cnblogs.com/huweiwill/p/5609146.html