Problem
Converting accented characters into their non-accented equivalents has been a challenge for some Go programmers. An attempt to implement a function using the "code.google.com/p/go.text/unicode/norm" package in Go 1.4 proved unsuccessful.
Solution
As of April 2015, an alternative approach is available with the introduction of the "runes" package, which includes a "Remove" function specifically designed for this purpose.
Go 1.5/1.6 Update
Looking ahead, Go 1.5 or 1.6 will likely bring a new "runes" package with transformation operations. This will offer a simplified solution using the "Remove" function, as seen in the following example:
<code class="go">package main import ( "fmt" "transform" "github.com/kjk/runes" "github.com/kjk/runes/example_test" ) func ExampleRemove() { t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) s, _, _ := transform.String(t, "résumé") fmt.Println(s) // Output: // resume } func main() { ExampleRemove() }</code>
The above is the detailed content of How Can I Remove Accents from Strings in Go?. For more information, please follow other related articles on the PHP Chinese website!