码迷,mamicode.com
首页 > 其他好文 > 详细

MYDELL

时间:2016-06-23 06:24:50      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

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";
}
}
}

MYDELL

标签:

原文地址:http://www.cnblogs.com/huweiwill/p/5609146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!