Home >Backend Development >Golang >How to Remove Accents from Strings in Go?
Go: Removing Accents from Strings
In Go, removing accents from strings can be achieved using normalization and a remove function. The following approach utilizes the runes package in Go 1.5 or later:
<code class="go">import ( "fmt" "runes" "code.google.com/p/go.text/transform" "code.google.com/p/go.text/unicode/norm" ) func RemoveAccents(s string) string { t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) result, _, _ := transform.String(t, s) return result } func main() { input := "résumé" fmt.Println(RemoveAccents(input)) // Output: resume }</code>
In this approach, we:
Note that this approach requires Go 1.5 or later, which introduces the runes package.
The above is the detailed content of How to Remove Accents from Strings in Go?. For more information, please follow other related articles on the PHP Chinese website!