Go strings Package Index()

Introduction

To find the position of a smaller string in a bigger string, use the Index function (it returns -1 if not found):

package main /*from  w  w  w  .  j a v a 2  s .  c  om*/

import ( 
    "fmt" 
    "strings" 
) 

func main() { 
    // func Index(s, sep string) int 
    fmt.Println(strings.Index("test", "e")) 
    // => 1 
} 



PreviousNext

Related