Erase 數(shù)組名
成都創(chuàng)新互聯(lián)主營(yíng)武昌網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶App定制開發(fā),武昌h5小程序開發(fā)搭建,武昌網(wǎng)站營(yíng)銷推廣歡迎武昌等地區(qū)企業(yè)咨詢
要注意,如果是固定數(shù)組,則所做頌有元素的值被初始化(字符型為空字符串,數(shù)值型為0),數(shù)組的大小是慧旦不變的;如果是動(dòng)態(tài)數(shù)組,則所有元素被刪除,內(nèi)存空間被回收,要重新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
比如數(shù)組a。里面有5個(gè)值,其中有3個(gè)是重復(fù)的?
如果這樣的慎巧話,很好辦哦。
新建一個(gè)數(shù)組b,然后遍歷要去除碼孝配的數(shù)組遲指a,
從a中把每一個(gè)都取出來(lái),和新建的b里面的去比,如果有相同的,則不放入b,
否則就放入數(shù)組b,直到循環(huán)結(jié)束。
來(lái)給你寫了個(gè)函數(shù),拿去用,不謝
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?'假設(shè)數(shù)組長(zhǎng)碼激悶敗度為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