lowwer in go
To convert a string to lowercase in the Go programming language, you can use the strings.ToLower()
function. Here are the steps to do it:
- Import the
strings
package: To use theToLower()
function, you need to import thestrings
package, which provides string manipulation functions.
import "strings"
- Declare a variable and assign a string value: Declare a variable and assign the string value that you want to convert to lowercase.
str := "HELLO WORLD"
- Use the
ToLower()
function: Call theToLower()
function from thestrings
package, passing the string variable as the argument. The function returns a new string with all uppercase characters converted to lowercase.
lower := strings.ToLower(str)
After these steps, the lower
variable will hold the lowercase version of the original string. You can use the fmt.Println()
function to print the lowercase string to the console.
Here is the complete example:
package main
import (
"fmt"
"strings"
)
func main() {
str := "HELLO WORLD"
lower := strings.ToLower(str)
fmt.Println(lower)
}
When you run this program, it will output:
hello world
That's how you can convert a string to lowercase in Go using the strings.ToLower()
function.