mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
e8436689ad
commit
e198a5086a
11 changed files with 38 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue