如何从richtext框中拆分字符串以**开头,以$结尾 [英] How to split the string from richtext box starts with ** and ends with $
问题描述
我正在使用串口从设备接收数据。我必须分开并单独显示以**开头并以$符号结尾的字符串。
这里的数据看起来像。
** 9-Realtech-00:00:09- 28/04 / 16-0 $ ** 10-REALTECH-00:00:10-28 / 04 / 16-1 $ ** 11-REALTECH-00:00:11-28 / 04 / 16-0 $ ** 12 REALTECH-00:00:12-28 / 04 / 16-1 $ ** 13-REALTECH-00:00:13-28 / 04 / 16-0 $ ** 14-REALTECH-00:00:14- 28/04 / 16-1 $ ** 15 REALTECH-00:00:15-28 / 04 / 16-0 $ ** 16 REALTECH-00:00:16-28 / 04 / 16-1 $ ** 17 REALTECH-00:00:17-28 / 04 / 16-0 $ ** 18-REALTECH-00:00:18-28 / 04 / 16-1 $ ** 19-REALTECH-00:00:19- 28/04 / 16-0 $ ** 20-Realtech-00:00:20-28 / 04 / 16-1 $。
我是什么尝试过:
我试过这段代码。
this.richTextBox1.Text + = data.ToString();
string x = richTextBox1.Text;
string match = x.Split(new string [] {**},StringSplitOptions .None)[1] .Split('$')[0] .Trim();
但它始终显示第一组数据9-Realtech -00:00:09-28 / 04 / 16-0\" 。它不会进入下一组数据。请帮我解决这个问题。
符号。
这里的数据看起来像。
** 9-Realtech-00:00:09- 28/04 / 16-0
** 10-REALTECH-00:00:10-28 / 04 / 16-1
** 11-REALTECH-00:00:11-28 / 04 / 16-0
I am receiving data from a device using serial port. I have to split and show separately the string which starts by ** and ends with $ symbol.
Here the data looks like.
**9-Realtech-00:00:09-28/04/16-0$**10-Realtech-00:00:10-28/04/16-1$**11-Realtech-00:00:11-28/04/16-0$**12-Realtech-00:00:12-28/04/16-1$**13-Realtech-00:00:13-28/04/16-0$**14-Realtech-00:00:14-28/04/16-1$**15-Realtech-00:00:15-28/04/16-0$**16-Realtech-00:00:16-28/04/16-1$**17-Realtech-00:00:17-28/04/16-0$**18-Realtech-00:00:18-28/04/16-1$**19-Realtech-00:00:19-28/04/16-0$**20-Realtech-00:00:20-28/04/16-1$.
What I have tried:
I have tried this code.
this.richTextBox1.Text += data.ToString();
string x = richTextBox1.Text;
string match = x.Split(new string[] { "**" }, StringSplitOptions.None)[1].Split('$')[0].Trim();
But it always shows the first set of data "9-Realtech-00:00:09-28/04/16-0". It is not going to next set of data's. Please help me to solve this.
symbol.
Here the data looks like.
**9-Realtech-00:00:09-28/04/16-0
**10-Realtech-00:00:10-28/04/16-1
**11-Realtech-00:00:11-28/04/16-0
这篇关于如何从richtext框中拆分字符串以**开头,以$结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!