Menu Close

Go – LastIndexByte() function in strings package in go

Here, We will learn about LastIndexByte() function in strings package in go.  LastIndexByte() function is used to get the index of the last instance of byte character in string in go golang.

Function prototype:

func LastIndexByte(str string, c byte) int

Return value:

LastIndexByte() function in strings package 
returns the index of the last instance of char
byte in string else -1 if c is not present in
str.

Example with code:

package main

import (
  "fmt"
  "strings"
)

func main() {

  s := strings.LastIndexByte("Go, Golang", 'l')
  fmt.Println(s)

  s = strings.LastIndexByte("Hello, Hii", 'H')
  fmt.Println(s)

  s = strings.LastIndexByte("Jonh, Kber", 'e')
  fmt.Println(s)

  s = strings.LastIndexByte("Abtir, Kupe", 'b')
  fmt.Println(s)
}

Output:

6
7
8
1

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, strings

Leave a Reply

Your email address will not be published.

Contact Us