strings.IndexByte() Function in Golang With Examples
Last Updated :
10 May, 2020
strings.IndexByte() Function in Golang returns the index of the first instance of the given byte in the original string. If the given byte is not available in the original string, then this method will return -1.
Syntax:
func IndexByte(str string, b byte) int
Here, str is the original string and b is a byte, whose we want to find the index value. Let us discuss this concept with the help of an example:
Example 1:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.IndexByte( "geeksforgeeks" , 'g' ))
fmt.Println(strings.IndexByte( "computerscience" , 's' ))
}
|
Output:
0
8
Example 2:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.IndexByte( "computerscience" , 'S' ))
fmt.Println(strings.IndexByte( "GFG" , 'f' ))
}
|
Output:
-1
-1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...