Skip to content

Instantly share code, notes, and snippets.

@Azhovan
Last active October 19, 2019 11:14
Show Gist options
  • Save Azhovan/0d3681b91187b39f256878c7a4e0dc7a to your computer and use it in GitHub Desktop.
Save Azhovan/0d3681b91187b39f256878c7a4e0dc7a to your computer and use it in GitHub Desktop.
change single character to Uppercase or lowercase (not unicode)
package main
import (
"bytes"
"fmt"
"unicode"
)
func main() {
str := []byte("hello THIS is me ")
output := bytes.Map(func(r rune) rune {
switch {
case r >= 'A' && r <= 'Z':
return unicode.ToLower(r)
default:
return unicode.ToUpper(r)
}
}, str)
fmt.Println(string(output))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment