strings.LastIndexFunc() Function in Golang With Examples

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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))
}

chevron_right


Output:

15
7

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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))
}

chevron_right


Output:

12
6



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.