keys := make([]string, 0)
...
for i, size := 0, len(keys); i < size; {
if strings.Contains(keys[i], "somestring") {
i++
} else {
keys = append(keys[:i], keys[i+1:]...)
size--
}
}
keys := make([]string, 0)
...
for i, size := 0, len(keys); i < size; {
if strings.Contains(keys[i], "somestring") {
i++
} else {
keys = append(keys[:i], keys[i+1:]...)
size--
}
}
本文标题:Golang slice 迭代过程中移除元素
本文链接:https://www.haomeiwen.com/subject/lwoxiftx.html
网友评论