Last updated on September 18, 2023
In golang, you can convert strings into lower case by using the ToLower() function from the string package. It accepts strings as an argument and converts into lower case.
The function ToLower() is case-sensitive, means that it should be written as ToLower(). If function name is written in lowercase or uppercase, an error will be returned. Therefore, it is important to ensure that the function name is written exactly as ToLower() to avoid any errors.
Syntax
strings.ToLower(any string)
Parameters
Return Value
The ToLower() function returns a lowercase string.
Usage
To use the ToLower() function you need to import the strings package into your go file. Below is the code that imports the strings package.
import (
"fmt"
"strings"
)
Once a file has a strings package then you can convert the string into lower through the function. Let’s do it by following code,
strings.ToLower("Golang Tutorials")
The above line of code converts the into lowercase. To check the output we can use Println() function from fmt package that prints the string to the console.
fmt.Println(strings.ToLower("Golang Tutorials"))
// Output: golang tutorials
In this example, the ToLower() function converts string into lower case.
Conclusion
This article demonstrates how you can convert strings in lowercase. To do that it uses the ToLower() function from the strings package. The ToLower() function accepts string as an argument and returns it into lowercase.