Open In App

strings.LastIndexFunc() Function in Golang With Examples

Last Updated : 10 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

strings.LastIndexFunc() Function in Golang returns the index of string s of the last Unicode code point, which satisfies func(c), or it returns -1 if no matches found.

Syntax:

func LastIndexFunc(s string, f func(rune) bool) int

Here, s is the string and func() is a function.

Return Value: It returns the integer.

Example 1:




// Golang program to illustrate the
// strings.LastIndexFunc() Function
package main
  
// importing fmt, strings and unicode
import (
    "fmt"
    "strings"
    "unicode"
)
  
// calling main method
func main() {
  
    // returns the last index of number.
    fmt.Println(strings.LastIndexFunc("GeeksForGeeks123", unicode.IsNumber))
  
    // returns the last index of number.
    fmt.Println(strings.LastIndexFunc("23Geeks1", unicode.IsNumber))
}


Output:

15
7

Example 2:




// Golang program to illustrate the
// strings.LastIndexFunc() Function
package main
  
// importing fmt, strings and unicode
import (
    "fmt"
    "strings"
    "unicode"
)
  
// calling main method
func main() {
  
    // returns the last index of letter.
    fmt.Println(strings.LastIndexFunc("GeeksForGeeks123", unicode.IsLetter))
  
    // returns the last index of letter.
    fmt.Println(strings.LastIndexFunc("23Geeks1", unicode.IsLetter))
}


Output:

12
6


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads