Compare strings with ==, > and <

Comparison is performed on raw bytes.

This works as you would expect for ascii (i.e. english) text but might not be what you want when strings use mixed case (e.g. “abba” is > “Zorro”) or use letters from non-english alphabets.

Compare with strings.Compare

You can also compare with strings.Compare but use ==, > and < instead as it has the same semantics.

Case-insensitive compare

Sometimes you want “Go” to equal “go”, which is not the case when using ==. You can do that using strings.EqualFold:

https://codeeval.dev/gist/f02f09cc8139ac473ce8a9cbc5900221

The exact rule is: both string are considered UTF-8-encoded strings and characters are compared using Unicode case-folding.

https://codeeval.dev/gist/e1c4352d17fadf7ae8231aa01fa1b507