package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(ShoutToWhisper("Hello, playground"))
fmt.Println(ShoutToWhisper("HELLO, PLAYGROUND"))
}
func ShoutToWhisper(s string) string {
if strings.ToUpper(s) == s {
s = strings.ToLower(s)
}
return s
}
By default Go will do sensible things with Unicode strings, but there is also a ToUpperSpecial if the language is known (it's not in our case) as it will disambiguate which runes to consider.
We use Go.
And it needs to be unicode friendly. So you can't rely on ASCII alone, and you need to be fine with unicode runes having a concept of upper and lower.
http://play.golang.org/p/1qwU7p3urR
By default Go will do sensible things with Unicode strings, but there is also a
ToUpperSpecial
if the language is known (it's not in our case) as it will disambiguate which runes to consider.