The strings
package is a Go
standard library package that contains functions to manipulate UTF-8 encoded strings.
ToLower()
methodIt provides the ToLower()
method, which can convert a string to a lower case.
This returns a copy of the string input where all the Unicode characters are mapped to its lowercase variant.
func ToLower(s string) string
This method takes a string s
as input.
It returns a string which is the lowercase of the input string.
First, we imported the fmt
and strings package to our program in the code below:
package mainimport ("fmt""strings")func main() {str1 := "NewYork"str2 := "CITY OF DREAMS"fmt.Println("Initial Strings")fmt.Println(str1);fmt.Println(str2);fmt.Println("\nAfter Calling ToLower()")fmt.Println(strings.ToLower(str1))fmt.Println(strings.ToLower(str2))}
After importing fmt
we call the ToLower()
method with New York
as the input string. This returns new york
as it returns a new string after converting it to lowercase.
We then call the ToLower()
method with CITY OF DREAMS
as the input string. This returns city of dreams
after converting the input to lowercase.
We show the output of all these operations using the Println()
method of the fmt
package.
The program prints below output and exits:
Initial Strings
NewYork
CITY OF DREAMS
After Calling ToLower()
newyork
city of dreams