I need to compare strings in Go.
The problem is: I want to compare accented words (café) with its non-accented form (cafe).
The first thing I do is converting my accented string
to its non-accented form with this:
you can run the code here: https://play.golang.org/p/-eRUQeujZET
But every time I do this transformation in a string it adds more runes in the end. The example above prints:
bytes: [99 97 102 101 0] string: cafe
As I need to compare the string returned from this process with its counterpart without the 'é' in the first place, I would need to remove the last rune
(0) from the []byte
.
After running some tests I perceived that the last 0s (sometimes it adds more than one) don't change the string representation.
Am I missing something? Can I just remove all zeros in the end of the []byte
?
Here is my code to remove the 0s and compare the strings:
https://play.golang.org/p/HoueAGI4uUx
As we can't work alone in this field, here the articles I read to get to where I am now:
https://blog.golang.org/strings
https://blog.golang.org/normalization