Bytes EqualFold ASCII Case
Compare byte slices case-insensitively with bytes.EqualFold, including a Unicode simple-fold pair that plain ASCII lowering would miss.
Code
package main
import (
"bytes"
"fmt"
)
func main() {
// EqualFold does Unicode simple folding, not a ToLower comparison
fmt.Println("ascii fold:", bytes.EqualFold([]byte("GoLang"), []byte("golang")))
fmt.Println("length differs:", bytes.EqualFold([]byte("go"), []byte("gopher")))
// U+212A KELVIN SIGN folds to ASCII k under simple folding
kelvin := []byte("\u212a")
fmt.Println("kelvin fold:", bytes.EqualFold(kelvin, []byte("k")))
fmt.Println("exact equal:", bytes.Equal(kelvin, []byte("k")))
// case-insensitive key lookup keeps the stored spelling intact
headers := map[string]string{"Accept": "application/json"}
for key, value := range headers {
if bytes.EqualFold([]byte(key), []byte("accept")) {
fmt.Println("header value:", value)
}
}
}How the snippet works
Structurally, expect the function main and nothing else.
Iteration happens inside for key, value := range headers — everything outside it runs once.
What to watch for
- By construction it needs nothing — no registry lookup, no lockfile entry.
Applying it
Look for the ascii fold:, length differs:, kelvin fold: prefixes when the file runs; they tie each line to its step.
Statements that matter most here
for key, value := range headers {
if bytes.EqualFold([]byte(key), []byte("accept")) {
fmt.Println("header value:", value)
}
}
Interactive Tools for This Topic
ASCII Table ReferenceLook up any ASCII code point 0-127 by decimal, hex, or character and see the binary, octal, and control-name view.Byte Size ConverterShow one byte count in every unit side by side, using decimal (kB/MB/GB) or binary (KiB/MiB/GiB) standards.Case ConverterConvert text between lowercase, uppercase, title, sentence, camelCase, snake_case, and kebab-case while preserving Unicode letters and numbers.cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.
FAQ
- What does Bytes EqualFold ASCII Case print when run?
- Invoke the file as-is — the `ascii fold:`, `length differs:`, `kelvin fold:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.