gpt4 book ai didi

arrays - 按位置从数组中删除元素

转载 作者:行者123 更新时间:2023-12-03 23:15:28 25 4
gpt4 key购买 nike

我试图弄清楚如何从数组中删除一个元素,如果它位于某个位置。我们还需要调整数组的大小。为了使示例更简单,让我们尝试删除数组中位置一的任何颜色(“green”、“blue”、“red”)。

Sub Example()

Dim pos
colors = Array("Green", "Blue", "Red")

pos = 1

colors(pos).Delete 'obviously this doesn't work but what would the correct protocol be?

End Sub

最佳答案

您也可以使用 Filter (如果值是唯一的,如本例中所示,则删除与 Green 匹配的任何字符串)。

Colors = Array("Green", "Blue", "Red", "Yellow", "Pink")
Colors = Filter(Colors, Colors(0), False)

关于arrays - 按位置从数组中删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com