How to find the index of elements in an array based on the substring in the elements in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	aList := []string{"bbc", "nnd", "wbb", "ccb", "qqd", "bbbbbo"}

	indexList := []int{}
	for i, s := range aList {
		if strings.Contains(s, "bb") {
			indexList = append(indexList, i)
		}
	}

	fmt.Println(indexList)
}


/*
run:

[0 2 5]

*/

 



answered Aug 18, 2024 by avibootz
...