strings.LastIndexFunc() Function in Golang With Examples
Last Updated :
10 May, 2020
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:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Println(strings.LastIndexFunc( "GeeksForGeeks123" , unicode.IsNumber))
fmt.Println(strings.LastIndexFunc( "23Geeks1" , unicode.IsNumber))
}
|
Output:
15
7
Example 2:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Println(strings.LastIndexFunc( "GeeksForGeeks123" , unicode.IsLetter))
fmt.Println(strings.LastIndexFunc( "23Geeks1" , unicode.IsLetter))
}
|
Output:
12
6
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...