go.nvim/playground/sampleApp/pkg/findAllSubStr.go
2022-01-19 08:44:01 +11:00

29 lines
555 B
Go

package pkg
import (
"strings"
)
func FindAllSubStr(stack, niddle string) (result []int) {
stack = strings.ToLower(stack)
niddle = strings.ToLower(niddle)
for idx := 1; idx >= 0; {
if idx = strings.Index(stack, niddle); idx != -1 {
result = append(result, idx)
stack = stack[idx+1:]
}
}
return result
}
func FindSubStr(stack, niddle string) (result int) {
stack = strings.ToLower(stack)
niddle = strings.ToLower(niddle)
for idx := 1; idx >= 0; {
if idx = strings.Index(stack, niddle); idx != -1 {
return idx
}
}
return -1
}