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:
C
Output:
C
Output:
func LastIndexFunc(s string, f func(rune) bool) intHere, 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))
}
15 7Example 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))
}
12 6