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
Article Tags :