strings.TrimRightFunc() Function returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.
Syntax:
func TrimRightFunc(s string, f func(rune) bool) string
Here, s is the string and func() is the method which satisfies the string characters.
Return Value: It returns the string after removing the trailing characters from the string.
Example 1:
// Golang program to illustrate // the strings.TrimRightFunc() Function package main // importing fmt, unicode and strings import ( "fmt"
"strings"
"unicode"
) // Calling Main method func main() { // Here we have a string. The function
// returns true for the letters
// and all other will trim out
// from the string only from Right
fmt.Print(strings.TrimRightFunc( "77GeeksForGeeks!!!" , func(r rune) bool {
return !unicode.IsLetter(r)
}))
} |
Output:
77GeeksForGeeks
Example 2:
// Golang program to illustrate // the strings.TrimRightFunc() Function package main // importing fmt, unicode and strings import ( "fmt"
"strings"
"unicode"
) // Calling Main method func main() { // Here we have a string. The function
// returns true for the letters
// and numbers as well
// and all other will trim out
// from the string only from left
fmt.Print(strings.TrimRightFunc( "!!!34GeeksForGeeks!!!!" , func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
}))
} |
Output:
!!!34GeeksForGeeks
Article Tags :