Menu Close

Go – LastIndexAny() function in strings package in go

Here, We will learn about LastIndexAny() function in strings package in go.  LastIndexAny() function is used to get the index of the last instance of any Unicode code point from chars in string in go golang.

Function prototype:

func LastIndexAny(str, chars string) int

Return value:

LastIndexAny() function in strings package 
returns the index of the last instance of any
Unicode code point from chars in string.
if no Unicode code point from chars is present
in string then it return -1.

Example with code:

package main

import (
  "fmt"
  "strings"
)

func main() {
  s := strings.LastIndexAny("Go Golang", "go")
  fmt.Println(s)

  s = strings.LastIndexAny("abcd c", "c")
  fmt.Println(s)

  s = strings.LastIndexAny("hello go", "lo")
  fmt.Println(s)

  s = strings.LastIndexAny("jon Sh", " ")
  fmt.Println(s)
}

Output:

8
5
7
3

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

https://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. Required fields are marked *