This question already has an answer here:
- Remove diacritics using Go 2 answers
Is there a Go library that can take Sjöström
as input and return Sjostrom
as output?
</div>
This question already has an answer here:
Is there a Go library that can take Sjöström
as input and return Sjostrom
as output?
</div>
You can use golang.org/x/text/unicode/norm
to handle this.
package main
import (
"fmt"
"io/ioutil"
"strings"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func main() {
isMn := func(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks
}
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
r := strings.NewReader("Sjöström")
x := transform.NewReader(r, t)
b, err := ioutil.ReadAll(x)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
See also: https://blog.golang.org/normalization