vb 如何在现有byte数组前端添加数据(数组里有数据),不想逐一读取,太影响速度
答案:1 悬赏:40 手机版
解决时间 2021-02-12 08:20
- 提问者网友:且恨且铭记
- 2021-02-11 22:51
vb 如何在现有byte数组前端添加数据(数组里有数据),不想逐一读取,太影响速度
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-02-12 00:06
如果我告诉你,字节数组可以像字符串一样进行拼接,而且可以把字符串直接赋值给字节数组,你会不会觉得很神奇或者不可思议?当然,由于VB的字符串使用Unicode编码,而字节数组要求ANSI编码,所以要把编码转换一下才行。下面就是个把两个字节数组合为一个的例子:
Private Sub Command1_Click()
Dim b1() As Byte, b2() As Byte, b3() As Byte, i As Integer
ReDim b1(4)
Print "第1个字节数组:";
For i = 0 To 4
b1(i) = 16 + i
Print Hex(b1(i)); " ";
Next
Print
ReDim b2(7)
Print "第2个字节数组:";
For i = 0 To 7
b2(i) = 160 + i
Print Hex(b2(i)); " ";
Next
Print
b3 = StrConv(StrConv(b1, vbUnicode) & StrConv(b2, vbUnicode), vbFromUnicode)
Print "合并后的字节数组:";
For i = 0 To UBound(b3)
Print Hex(b3(i)); " ";
Next
End Subb3 = StrConv(StrConv(b1, vbUnicode) & StrConv(b2, vbUnicode), vbFromUnicode)
这句我单独解释一下:这是先把两个字节数组b1和b2分别转为Unicode编码,它们就变成了VB的字符串(真的哦!),然后把两个字符串拼接成一个字符串,再转为ANSI编码,最后赋值给一个动态字节数组b3,OK搞定!
Private Sub Command1_Click()
Dim b1() As Byte, b2() As Byte, b3() As Byte, i As Integer
ReDim b1(4)
Print "第1个字节数组:";
For i = 0 To 4
b1(i) = 16 + i
Print Hex(b1(i)); " ";
Next
ReDim b2(7)
Print "第2个字节数组:";
For i = 0 To 7
b2(i) = 160 + i
Print Hex(b2(i)); " ";
Next
b3 = StrConv(StrConv(b1, vbUnicode) & StrConv(b2, vbUnicode), vbFromUnicode)
Print "合并后的字节数组:";
For i = 0 To UBound(b3)
Print Hex(b3(i)); " ";
Next
End Subb3 = StrConv(StrConv(b1, vbUnicode) & StrConv(b2, vbUnicode), vbFromUnicode)
这句我单独解释一下:这是先把两个字节数组b1和b2分别转为Unicode编码,它们就变成了VB的字符串(真的哦!),然后把两个字符串拼接成一个字符串,再转为ANSI编码,最后赋值给一个动态字节数组b3,OK搞定!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯