Welcome To Golang By Example

Convert string to lowercase in Go (Golang)

Table of Contents

Overview

In GO string are UTF-8 encoded. strings package of GO provides a ToLower method that can be used to convert all Unicode letters to their lower case. This method will return the copy of the string as in GO string are immutable.

Below is the signature of the function

func ToLower(s string) string

Let’s look at the working code

Code:

package main

import (
    "fmt"
    "strings"
)

func main() {
    res := strings.ToLower("ABC")
    fmt.Println(res)

    res = strings.ToLower("ABC12$a")
    fmt.Println(res)
}

Output:

abc
abc12$a