RosettaCodeData/Task/String-case/Go/string-case-1.go

29 lines
816 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"strings"
"unicode"
"unicode/utf8"
)
func main() {
show("alphaBETA")
show("alpha BETA")
// Three digraphs that should render similar to DZ, Lj, and nj.
show("DŽLjnj")
// Unicode apostrophe in third word.
show("o'hare O'HARE ohare don't")
}
func show(s string) {
fmt.Println("\nstring: ",
s, " len:", utf8.RuneCountInString(s), "runes") // DZLjnj
fmt.Println("All upper case: ", strings.ToUpper(s)) // DZLJNJ
fmt.Println("All lower case: ", strings.ToLower(s)) // dzljnj
fmt.Println("All title case: ", strings.ToTitle(s)) // DzLjNj
fmt.Println("Title words: ", strings.Title(s)) // Dzljnj
fmt.Println("Swapping case: ", // DzLjNJ
strings.Map(unicode.SimpleFold, s))
}