我需要将用户输入的每个字符的ASCII码存储到一个数组中,然后在转换后的文本框中显示ASCII
这些是我的声明
Dim modByte() As Integer 'the array where i need to put each ascii code
Dim modValue As String 'modvalue = mod_TB_Input.Text
这是我用来将ascii放入数组的代码
For Each ch As Char In modValue
For Each i As Integer In modByte
modByte(i) = Asc(ch)
mod_TB_convert.Text = modByte(i) 'converted(textbox) = mod_tb_convert
Next
Next
答案 0 :(得分:0)
我可能首先构建数组然后输出...你的代码也没有工作,你需要在数组增长时重新保存数组 - 例如。
Dim modByte() As Integer
Dim modValue As String = mod_TB_Input.Text
Dim counter As Integer = 0
For Each ch As Char In modValue
counter += 1
ReDim Preserve modByte(counter - 1)
modByte(counter - 1) = Asc(ch)
Next
mod_TB_convert.Text = String.Join("", modByte)
但是 - 你可以避免这一切并在一行中完成......
mod_TB_convert.Text = String.Join("", mod_TB_Input.Text.Select(Function(t) Asc(t)))