In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
In Go string, you are allowed to convert a string in the lowercase using ToLower() function. This function returns a copy of the given string in which all the Unicode letters mapped into lower case. This function is defined under strings package, so you have to import strings package in your program to access this function.
Syntax:
func ToLower(str string) string
Here, str represents a string which you want to convert to lowercase.
Example:
package main
import (
"fmt"
"strings"
)
func main() {
str1 := "WelcomE, GeeksforGeeks**"
str2 := "$$This is the, tuTorial oF Golang##"
str3 := "HELLO! GOLANG"
str4 := "lowercase conversion"
fmt.Println( "Strings (before):" )
fmt.Println( "String 1: " , str1)
fmt.Println( "String 2:" , str2)
fmt.Println( "String 3:" , str3)
fmt.Println( "String 4:" , str4)
res1 := strings.ToLower(str1)
res2 := strings.ToLower(str2)
res3 := strings.ToLower(str3)
res4 := strings.ToLower(str4)
fmt.Println( "\nStrings (after):" )
fmt.Println( "Result 1: " , res1)
fmt.Println( "Result 2:" , res2)
fmt.Println( "Result 3:" , res3)
fmt.Println( "Result 4:" , res4)
}
|
Output:
Strings (before):
String 1: WelcomE, GeeksforGeeks**
String 2: $$This is the, tuTorial oF Golang##
String 3: HELLO! GOLANG
String 4: lowercase conversion
Strings (after):
Result 1: welcome, geeksforgeeks**
Result 2: $$this is the, tutorial of golang##
Result 3: hello! golang
Result 4: lowercase conversion
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 Aug, 2019
Like Article
Save Article