Go strings.ToLower
Normalize an ASCII course tag to lowercase before grouping records.
A simple example
strings.ToLower
- Start with "AB"
- Do this Convert to lowercase
- Result "ab"
package main
import (
"fmt"
"strings"
)
func main() {
value := "AB"
fmt.Println(strings.ToLower(value))
}
ab
Syntax
strings.ToLower(value)
Run these examples in Go
Save one example at a time as main.go. Use Go 1.21 or later.
go run main.goNormalize a course tag
A course catalog accepts short tags from several editors. Bring a new tag into the chosen case convention before using it in the public listing.
package main
import (
"fmt"
"strings"
)
func main() {
value := "BIO-101"
fmt.Println(strings.ToLower(value))
}
bio-101
Digits and the hyphen stay unchanged.
Normalize a receipt status
Two terminals can enter the same short label with different capitalization or padding. Normalize the incoming spelling before lookup so the stored identifiers can follow a consistent convention.
package main
import (
"fmt"
"strings"
)
func main() {
value := "PAID"
fmt.Println(strings.ToLower(value))
}
paid
The same status can be compared consistently in this ASCII data set.
Read a parcel sorting code
The depot scans a parcel marked NC-17. The search index stores the complete identifier in lowercase. Which key goes into the index?
What to watch for
Keep the original spelling for display names. Machine tags here use only ASCII letters and digits.