Last active
October 19, 2019 11:14
-
-
Save Azhovan/0d3681b91187b39f256878c7a4e0dc7a to your computer and use it in GitHub Desktop.
change single character to Uppercase or lowercase (not unicode)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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