I want to find the index of all occurrences of a string contained within a byte array.
func findAllOccurrences(data []byte, searches []string) map[string][]int {
var results map[string][]int
for _, search := range searches {
firstMatch = bytes.Index(data, []byte(search))
results[search] = append(results[search], firstMatch)
// How do I find subsequent the rest of the matches?
}
return results
}
Finding the first Index()
is simple enough, but how can I find all of them in an idiomatic way without consuming unnecessary memory?