Use strings.TrimFunc to trim suffixes/prefixes from strings

Published: 2021-06-11 in golang

Found cool function in the strings package today, TrimFunc!

This allows you to remove any character (rune) you want from the suffix or prefix of a string by passing a function and returning true if something should be removed.


strings.TrimFunc("¡¡¡Hello, Gophers!!!", func(r rune) bool {
		return !unicode.IsLetter(r) && !unicode.IsNumber(r)