从字符串获取字符(C#窗口应用程序)
问题描述:
我开发了串口数据接收软件.
假设我有像这样的数据,但是每次都不一样.每次获得不同的数据时,以下都是数据示例.
I developed serial port data receiving software.
Suppose I have data like this data, but it is not same every time. Every time I get different data, following is an example of data.
FF FF FF FF 82 00 01 02 03 04 00 05 01 02 03 04 05 ee ed
我想这样破坏数据:
I would like to break the data like this:
FF FF FF FF
82
00 01 02 03 04
00
05
01 02 03 04 05
ee
ed
答
您将必须对其进行处理并加以解决!抱歉,但是没有为此功能的.NET功能,我必须对为什么在这些位置处中断进行假设:即序列可以,但在相同的运行结束时中断或增加. />
我这样做的方法是将字符串转换为字节流,然后将其中断,因为这样可以更轻松地确定序列的开始和结束位置.
第一部分非常简单:
You will have to process it and work it out! Sorry, but there is no .NET function for this, and I would have to make assumption about why you are breaking in those places: i.e. sequences are ok, but break at the end of a run of the same, or increasing.
The way I would do it, is to convert the string into a byte stream, then break that because it will be easier to work out where sequences start and end.
The first part is very simple:
string s = "FF FF FF FF 82 00 01 02 03 04 00 05 01 02 03 04 05 ee ed";
byte[] bytes = SoapHexBinary.Parse(s).Value;