strings.TrimRightFunc() Function in Golang With Examples
Last Updated :
10 May, 2020
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:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Print(strings.TrimRightFunc( "77GeeksForGeeks!!!" , func(r rune) bool {
return !unicode.IsLetter(r)
}))
}
|
Output:
77GeeksForGeeks
Example 2:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Print(strings.TrimRightFunc( "!!!34GeeksForGeeks!!!!" , func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
}))
}
|
Output:
!!!34GeeksForGeeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...