我将ASCII码解码回字符串时遇到问题。
首先,我从用户那里获取文本输入并将其转换为连续分配给标签的ASCII码。比我想将它从该标签转换回普通字符串。但是我收到一个随机符号而不是字符串。
我相信这是因为该函数无法区分某个字母的代码何时开始以及何时完成。任何想法如何设置分隔符或类似的东西?如果它当然会解决问题
这是我使用的代码:
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Label3.Text = ""
For x As Integer = 1 To TextBox3.Text.Length
Label3.Text &= CStr(Asc(Mid$(TextBox3.Text, x, 1)))
Next
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
Label4.Text = ""
For x As Integer = 1 To Label3.Text.Length
Label4.Text &= Chr(Mid$(Label3.Text, x, 1))
Next
End Sub
答案 0 :(得分:0)
试试这个。
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Label3.Text = ""
For x As Integer = 1 To TextBox3.Text.Length
Label3.Text &= CStr(Asc(Mid$(TextBox3.Text, x, 1))) & "|"
Next
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Label4.Text = ""
Dim value As Integer = 0
Dim buf As String = ""
For x As Integer = 1 To Label3.Text.Length
If Mid$(Label3.Text, x, 1) <> "|" Then
buf &= Mid$(Label3.Text, x, 1)
Else
Label4.Text &= Chr(Val(buf))
buf = ""
End If
Next
End Sub