OneBite.Dev - Coding blog in a bite size

convert a string to lowercase in Go

Code snippet on how to convert a string to lowercase in Go

package main

import (
	"fmt"
	"strings"
)
func main() {
	string := "HELLO WORLD"
	string = strings.ToLower(string)
	fmt.Print(string)
}

The code begins by importing fmt and strings packages. This allows access to all of the functions provided by the packages. The code then declares a string variable and assigns it the value “HELLO WORLD”. The strings.ToLower() function is then used on the string. This function changes the string to all lowercase letters. Lastly the string is printed out. This code can be used to quickly and easily convert a string to all lowercase letters.

go