Go – String to Lowercase

To convert string to lowercase in Go programming, callstrings.ToLower() function and pass the string as argument to this function.

In this tutorial, we will learn how to convert a string to lower case using strings.ToLower() function, with examples.

Syntax

The syntax of ToLower() function is

strings.ToLower(str)

where

  1. strings is the package.
  2. ToLower is the function name.
  3. str is the input string.

strings.ToLower() function returns a string with all characters in the original string converted to lower case.

ADVERTISEMENT

Example

In the following program, we will take a string str containing a mix of lower and upper case alphabets and convert it to lower case.

example.go

package main

import (
	"fmt"
	"strings"
)

func main() {
	var str = "HelLo WoRld"
	var str_lower = strings.ToLower(str)
	fmt.Printf(str_lower)
}

Output

hello world

Conclusion

In this Golang Tutorial, we learned how to convert a string to lower case using strings.ToLower() function.