-
-
Save oxyno-zeta/cadedc75c720a5e5cc2acbf2d8daaeea to your computer and use it in GitHub Desktop.
Golang remove accents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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