Go Language Tutorial
In Go programming, Built in strings package has ToUpper and ToLower functions to get all the string data in lower or upper case characters.
Need to import strings package in go program to use ToUpper and ToLower functions to convert the string case.
ToUpper function is used to get all the string data in upper case characters.
package main import ( "fmt" "strings" ) func main() { var str1, str2 string str1 = "CodingPointer.com!" // converts string str1 in upper case and assigns to str2 str2 = strings.ToUpper(str1) fmt.Printf("Upper Case '%s': %s\n", str1, str2) }Output:
$ go build string-upper.go $ ./string-upper Upper Case 'CodingPointer.com!': CODINGPOINTER.COM!
ToLower function is used to get all the string data in lower case characters.
package main import ( "fmt" "strings" ) func main() { var str1, str2 string str1 = "CodingPointer.com!" // converts string str1 in lower case and assigns to str2 str2 = strings.ToLower(str1) fmt.Printf("Lower Case '%s': %s\n", str1, str2) }Output:
$ go build string-lower.go $ ./string-lower Lower Case 'CodingPointer.com!': codingpointer.com!« Previous Next »