本文介绍了字符串十六进制到字节,vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力完成一项简单的任务。乍一看,至少看起来应该是这样。我有一个 TextBox
,其中包含十六进制字符串。它们的长度始终是两个十六进制数字(例如 AA
)。我想将 textbox3.Text
转换为 Byte
。
I'm struggling with an easy task. At least it looks like it should be, at first sight. I have a TextBox
that contains HEX strings. They are always two hex digits in length (e.g. AA
). I want to convert textbox3.Text
to a Byte
.
这是我到目前为止的内容:
Here's what I have so far:
Dim checking As String = textbox3.Text
Dim a = Convert.ToByte(checking)
RichTextBox1.Text = a.ToString
但是它会引发 SystemFormatException
。
推荐答案
方法提供了一个重载,该重载采用字符串参数,后跟一个数字,该数字指定字符串中值的基数。十六进制为16。因此,例如:
The Convert.ToByte method provides an overload which takes a string argument followed by a number specifying the base of the value in the string. Hexadecimal is base-16. So, for instance:
Dim checking As String = textbox3.Text
Dim a As Byte = Convert.ToByte(checking, 16)
RichTextBox1.Text = a.ToString()
这篇关于字符串十六进制到字节,vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!