strings.LastIndexByte() Function in Golang With Examples
Last Updated :
10 May, 2020
strings.LastIndexByte() Function in Golang returns the index of the last 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 LastIndexByte(str string, b byte) int
Here, str is the original string and b is a byte, whose we want to find the last index value.
Return Value: It returns the integer.
Example 1:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.LastIndexByte( "geeksforgeeks" , 'g' ))
fmt.Println(strings.LastIndexByte( "geekgeekgeek" , 'k' ))
}
|
Output:
8
11
Example 2:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.LastIndexByte( "GeeksForGeeks" , 'g' ))
fmt.Println(strings.LastIndexByte( "GeeKGeeKGeeK" , 'k' ))
}
|
Output:
-1
-1
Share your thoughts in the comments
Please Login to comment...