How can we convert a string into lowercase in Golang?

String in Golang is different from other programming languages like Java and C++. Strings in the Go language are a series of bytes that usually represents the text characters. Now, the bytes in the strings can be represented in the Unicode Text using the UTF-8 encoding, because of which we can represent any language present in the world using Go strings.

Now, how can we convert a string into its lowercase representation?

We can easily do that by using the ToLower() function of the strings package. This post will look at how we can convert a string to lowercase using the ToLower() function.

package main

import (
	"fmt"
	"strings"
)

func main() {

	string1 := "**Hi CODEKRU**"
	string2 := "LeaRnINg GoLang"
	string3 := "lowercase string"

	fmt.Println("Original Strings: ")
	fmt.Println(string1)
	fmt.Println(string2)
	fmt.Println(string3)

	string1 = strings.ToLower(string1)
	string2 = strings.ToLower(string2)
	string3 = strings.ToLower(string3)

	fmt.Println()
	fmt.Println("After using ToLower() method: ")
	fmt.Println(string1)
	fmt.Println(string2)
	fmt.Println(string3)

}

Output –

**hi codekru**
learning golang
lowercase string

That’s it. We hope that you have gotten your solution. If you have any doubts or concerns, please feel free to write us in the comments or mail us at admin@codekru.com.

Liked the article? Share this on

Leave a Comment

Your email address will not be published. Required fields are marked *