Created
May 12, 2020 22:26
-
-
Save massahud/16ff7fb7001194ead41f651563315085 to your computer and use it in GitHub Desktop.
Replace accentuated characters in go
This file contains 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/runes" | |
"golang.org/x/text/transform" | |
"golang.org/x/text/unicode/norm" | |
) | |
func main() { | |
transf := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) | |
str := "Mégane" | |
output, _, e := transform.String(transf, str) | |
if e != nil { | |
panic(e) | |
} | |
fmt.Println("before", str, "after", output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment