How to get the index of the first instance of a character in a string with Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Println(strings.IndexByte("go php", 'p'))
	fmt.Println(strings.IndexByte("go php go", 'g'))
	fmt.Println(strings.IndexByte("go php", 'e'))
}



/*
run:
 
3
0
-1
 
*/

 



answered Aug 20, 2020 by avibootz
...