How to find the index of substring in a string with Go

2 Answers

0 votes
package main 
  
import ( 
    "fmt"
    "strings"
) 
  
func main() { 
    s := "go java c++ php python"
  
    r := strings.Index(s, "php") 
  
    fmt.Println(r) 
}  
   
     
/*
run:
     
12
     
*/

 



answered Aug 3, 2020 by avibootz
0 votes
package main 
  
import ( 
    "fmt"
    "strings"
) 
  
func main() { 
    s := "go java c++ php python"
  
    r := strings.Index(s, "c#") 
  
    fmt.Println(r) 
}  
   
     
/*
run:
     
-1
     
*/

 



answered Aug 3, 2020 by avibootz
...