我正在使用VB-2013。我需要将一个十六进制字符串发送到文本文件。不幸的是,由于另一个需要从文本文件中读取此十六进制的程序,我无法将其作为原始十六进制发送。我还需要操作一些值来创建校验和。截至目前,当我将它们写入文本文件时,它们显示为十进制。我想知道如何将十六进制字符串转换为ASCII等效字符?
这是主要的应用程序
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
fileN = TextBox1.Text
path = ("**************" + fileN + ".txt")
Dim fs As New FileStream(path, FileMode.Create, FileAccess.Write)
Dim sw As New StreamWriter(fs)
sw.WriteLine(intV(holder, TextBox2.Text))
sw.Flush()
fs.Close()
End Sub
这是我写作的好处
Public Function intV(ByVal arr() As String, r As String)
i = 0
textH = Convert.ToInt16(r)
arr(0) = &H8E
arr(1) = &H71
arr(2) = &H7
arr(3) = &H98
arr(4) = &HD
arr(5) = textH
Do Until arr.Length - 1
sB = sB + arr(i)
i = i + 1
Loop
arr(6) = sB
i = 0
hold = Join(arr, " ")
Return hold
End Function
修改
在textbox2
中输入值为60的文本文件142 113 7 152 13 60 0
答案 0 :(得分:1)
hold = String.Join(" ", (From i In arr Select String.Format("{0:X}", i)).ToArray)