Code-Memo

Comparing strings

Equality

== compares byte-wise equality for strings (UTF-8 sequences). For normalized Unicode text, consider unicode/norm before comparing.

if s1 == s2 {
	// identical UTF-8 bytes
}
Order

Use strings.Compare(a, b) returning -1/0/1, or relational operators < etc. on strings for lexicographic byte order (not always linguistic sort order).

Collations

For locale-aware sorting, use golang.org/x/text/collate or a dedicated library — not plain < on arbitrary user text.

Case folding
import "strings"

strings.EqualFold("Go", "go") // true
Prefix / suffix / contains
strings.HasPrefix(s, "http://")
strings.HasSuffix(s, ".go")
strings.Contains(s, "needle")
Interning

strings.Intern (available in newer Go via weak/unique patterns) or manual maps reduce memory for repeated string keys — only when profiling shows duplication cost.