Skip to content

Instantly share code, notes, and snippets.

@massahud
Created May 12, 2020 22:26
Show Gist options
  • Save massahud/16ff7fb7001194ead41f651563315085 to your computer and use it in GitHub Desktop.
Save massahud/16ff7fb7001194ead41f651563315085 to your computer and use it in GitHub Desktop.
Replace accentuated characters in go
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