Answer the question
In order to leave comments, you need to log in
How to remove elements from slice []string containing specific text?
Greetings, stuck on a seemingly simple task.
there is a slice []string
for example
[zip_243234, html_2222, zip_123123, zip_6576767, css_2134234]
how to make the slice become
[zip_243234, zip_123123, zip_6576767]
?
Thank you)
Answer the question
In order to leave comments, you need to log in
Nice set of operations on slices: https://github.com/golang/go/wiki/SliceTricks
This problem needs "Filtering without allocating"
b := a[:0]
for _, x := range a {
if x != "html_2222" && x != "css_2134234" {
b = append(b, x)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question