strings.LastIndexByte() Function in Golang With Examples

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the
// strings.LastIndexByte() Function
package main
  
// importing fmt and strings
import (
    "fmt"
    "strings"
)
  
// calling main method
func main() {
  
    // returns the last index of 'g' in string.
    fmt.Println(strings.LastIndexByte("geeksforgeeks", 'g'))
  
    // returns the last index of 'k' in string.
    fmt.Println(strings.LastIndexByte("geekgeekgeek", 'k'))
}

chevron_right


Output:

8
11

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the
// strings.LastIndexByte() Function
package main
  
// importing fmt and strings
import (
    "fmt"
    "strings"
)
  
// calling main method
func main() {
  
    // performs case-insensitive search(returns -1).
    fmt.Println(strings.LastIndexByte("GeeksForGeeks", 'g'))
  
    // performs case-insensitive search(returns -1).
    fmt.Println(strings.LastIndexByte("GeeKGeeKGeeK", 'k'))
}

chevron_right


Output:

-1
-1



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.