在文本框中显示一个字节数组

编程入门 行业动态 更新时间:2024-10-11 09:23:52
本文介绍了在文本框中显示一个字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 c#中有代码从串口读取一个字节数组。 我必须在文本框中显示通过串口接收的这个字节数组数据。 这个字节数组需要编辑才能从发送回应用程序。 任何人都可以帮我找到解决方案。 如何在文本框中显示字节数组数据。

解决方案

问题尚未完全定义。字节可以表示文本,这是一个可能的选项,其他选项将字节显示为十六进制字符串的单独十进制。或其他。 第一个选项显示在解决方案1中,它也包含ASCII,但编码可能会有所不同,具体取决于某些要求。 第二个选项可能需要类似的内容:

byte [] example = new byte { 1 , 2 , 3 ,}; System.StringBuilder stringBuilder = new System.StringBuilder(); foreach ( byte 示例) stringBuilder.Append( byte .ToString()+ ,); // 可以添加格式参数 yourTextBox = stringBuilder.ToString.Trim(); // 不是最有效的,只是为了简单

-SA

你可以这样做:

byte [] example = new byte {0x01,0x02,0x03}; YourTextBox.Text = System.Text.Encoding.UTF8.GetString(示例)

Hi, I have code in c# that read a byte array from a serial port. I have to display this byte array data received via serial port, in a text box. This byte array is needed to edit from the for send back to an application. Anybody please help me to find a solution. How to display byte array data in textbox.

解决方案

The problem is not fully defined. The bytes can represent text, this is one possible option, and other option would be showing the bytes as separate decimal of hexadecimal strings. Or something else. First options is shown in Solution 1, which also covers ASCII, but the encoding can be different, depending on some requirements. The second option may require something like;

byte[] example = new byte { 1, 2, 3, }; System.StringBuilder stringBuilder = new System.StringBuilder(); foreach(byte in example) stringBuilder.Append(byte.ToString() + ", "); // a format parameter can be added yourTextBox = stringBuilder.ToString.Trim(); // not the most efficient, just for simplicity

—SA

You could do this:

byte[] example = new byte { 0x01, 0x02, 0x03 }; YourTextBox.Text = System.Text.Encoding.UTF8.GetString(example)

更多推荐

在文本框中显示一个字节数组

本文发布于:2023-11-07 15:56:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字节   框中   文本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!