Erase 数组名
成都创新互联主营武昌网站建设的网络公司,主营网站建设方案,重庆App定制开发,武昌h5小程序开发搭建,武昌网站营销推广欢迎武昌等地区企业咨询
要注意,如果是固定数组,则所做颂有元素的值被初始化(字符型为空字符串,数值型为0),数组的大小是慧旦不变的;如果是动态数组,则所有元素被删除,内存空间被回收,要重新ReDim才能使用。Private Sub Form_Click()Dim a(9) As Integer, i As IntegerRandomizePrint "前胡扰清除前:"For i = 0 To 9 a(i) = Rnd * 100 Print a(i);NextPrintErase aPrint "清除后"For i = 0 To 9 Print a(i);NextPrintEnd Sub
比如数组a。里面有5个值,其中有3个是重复的?
如果这样的慎巧话,很好办哦。
新建一个数组b,然后遍历要去除码孝配的数组迟指a,
从a中把每一个都取出来,和新建的b里面的去比,如果有相同的,则不放入b,
否则就放入数组b,直到循环结束。
来给你写了个函数,拿去用,不谢
Function RemoveAt(Of T)(ByVal arr As T(), ByVal index 雀芹As Integer) As T()
Dim uBound = arr.GetUpperBound(0)
Dim lBound = arr.GetLowerBound(0)
Dim arrLen 则岁罩= uBound - lBound
If index lBound OrElse index uBound Then
Throw New ArgumentOutOfRangeException( _
String.Format("Index must be from {0} to {1}.", lBound, uBound))
Else
孙闹 Dim outArr(arrLen - 1) As T
Array.Copy(arr, 0, outArr, 0, index)
Array.Copy(arr, index + 1, outArr, index, uBound - index)
Return outArr
End If
End Function
For i = 0 To 10 '假设数组长码激闷败度为10
If a(i) = 3 Then
For j = i To 迟罩袜10 - 1
a(j) = a(j + 1)
Next j
ReDim Preserve a(10 - 1)
Exit For
End If
Next i
If i 10 Then
For k = 0 To 10 - 1
Print a(k)
Next
Else
For k = 0 To 10
Print a(k)
Next
End If