strings: Contains

Tiny helper to avoid strings.Index(s, sub) != -1

R=rsc, r2, r
CC=golang-dev
https://golang.org/cl/2265044
This commit is contained in:
Brad Fitzpatrick 2010-11-01 14:32:48 -07:00 committed by Rob Pike
parent e8436689ad
commit e198a5086a
11 changed files with 38 additions and 12 deletions

View file

@ -61,6 +61,11 @@ func Count(s, sep string) int {
return n
}
// Contains returns true if substr is within s.
func Contains(s, substr string) bool {
return Index(s, substr) != -1
}
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
func Index(s, sep string) int {
n := len(sep)