strings.TrimFunc() Function in Golang With Examples
Last Updated :
03 May, 2020
strings.TrimFunc() Function in Golang is used to returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.
Syntax:
func TrimFunc(s string, f func(rune) bool) string
Here, s is the string and function checks the value of rune and returns true if it can be trimmed.
Return Type: It returns the string after removing the specified characters from string.
Example 1:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Print(strings.TrimFunc( "77GeeksForGeeks!!!" , func(r rune) bool {
return !unicode.IsLetter(r)
}))
}
|
Output:
GeeksForGeeks
Example 2:
package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
fmt.Print(strings.TrimFunc( "1234GeeksForGeeks!!!!" , func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
}))
}
|
Output:
1234GeeksForGeeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...