求该数组对比的简化代码,感谢各位热心人!
假设:
Dim a() As Byte, b() As Byte ReDim a(2) a(0) = 2: a(1) = 1: a(2) = 1 ……这里通过某些操作使得 b 也拥有了3个有效元素,但内容随机
Sub GetBytes(souByte() As Byte, conByte() As Byte) Dim LenSouByte As Long, LenConByte As Long Dim i As Long, j As Long Dim Length As Long LenSouByte = UBound(souByte) LenConByte = UBound(conByte) For i = LenSouByte - LenConByte To LenSouByte j = i Length = 0 Do While (souByte(j) = conByte(Length)) j = j + 1 Length = Length + 1 If j > LenSouByte Then Exit For Loop Next i ReDim Preserve souByte(LenSouByte + (LenConByte + 1 - Length)) j = LenConByte For i = UBound(souByte) To LenSouByte + 1 Step -1 souByte(i) = conByte(j) j = j - 1 NextEnd Sub