I am complete newbie in Golang, I am trying to remove elements in one slice based on the elements in another slice.
e.g.
input slice : urlList := []string{"test", "abc", "def", "ghi"}
elements to remove slice : remove := []string{"abc", "test"}
expected output slice : urlList := []string{"def", "ghi"}
This is what I tried.
func main() {
urlList := []string{"test", "abc", "def", "ghi"}
remove := []string{"abc", "test"}
loop:
for i, url := range urlList {
for _, rem := range remove {
if url == rem {
urlList = append(urlList[:i], urlList[i+1:]...)
continue loop
}
}
}
for _, v := range urlList {
fmt.Println(v)
}
}
But it's not working as I expected. I don't know what I am missing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…