Skip to content

Instantly share code, notes, and snippets.

@oxyno-zeta
Forked from tkrajina/remove_accents.go
Last active July 8, 2021 09:05
Show Gist options
  • Save oxyno-zeta/cadedc75c720a5e5cc2acbf2d8daaeea to your computer and use it in GitHub Desktop.
Save oxyno-zeta/cadedc75c720a5e5cc2acbf2d8daaeea to your computer and use it in GitHub Desktop.
Golang remove accents
package main
import (
"fmt"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func main() {
s := "Yoùr Śtring šđč枊ĐČĆŽ Ötzi's Nationalität èàì"
b := make([]byte, len(s))
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
_, _, e := t.Transform(b, []byte(s), true)
if e != nil {
panic(e)
}
fmt.Println(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment