Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Types in Go
  • Go Keywords
  • Go Control Flow
  • Go Functions
  • GoLang Structures
  • GoLang Arrays
  • GoLang Strings
  • GoLang Pointers
  • GoLang Interface
  • GoLang Concurrency
Open In App
Next Article:
How to convert a string in lower case in Golang?
Next article icon

How to convert a string in lower case in Golang?

Last Updated : 12 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Go, converting a string to lowercase is a common operation that can be accomplished easily using the strings package. This package provides various string manipulation functions, including the ToLower function, which converts all Unicode characters in a string to their lowercase equivalent.

Example

Input: Hello, Geeks!
Output: hello, geeks!
Explanation: The ToLower function in Go converts all Unicode characters in a string to their lowercase equivalent, returning a new string.

Syntax

The syntax of the ToLower function is as follows:

lowerS := strings.ToLower(s)

Where:

  • s is the original string you want to convert to lowercase.
  • lowerS is the new string with all characters converted to lowercase.

Convert a String to Lower Case

In Go, converting a string to lowercase is a common operation that can be accomplished easily using the ToLower function.

Syntax

The syntax of the ToLower function is as follows:

lowerS := strings.ToLower(s)

Example

Go
package main import (     "fmt"     "strings" ) func main() {     // Initial string     s := "Hello, Geeks!"     fmt.Println("", s)      // Converting to lower case     lowerS := strings.ToLower(s)     fmt.Println("", lowerS) } 

Output
 Hello, Geeks!  hello, geeks! 

Converting Multiple Strings

You can also convert multiple strings to lower case by using a loop.

Syntax

for i, s := range phrases {
phrases[i] = strings.ToLower(s)
}

Where:

  • phrases is a slice of strings that you want to convert to lower case.

Example

Go
package main import (     "fmt"     "strings" ) func main() {     // Initial strings     phrases := []string{"Hello, Geeks!", "GoLang is Fun!"}          fmt.Println("", phrases)          // Converting to lower case     for i, s := range phrases {         phrases[i] = strings.ToLower(s)     }          fmt.Println("", phrases) } 

Output
 [Hello, Geeks! GoLang is Fun!]  [hello, geeks! golang is fun!] 

Handling User Input

You can also convert user input to lower case.

Syntax

fmt.Scanln(&userInput)
lowerInput := strings.ToLower(userInput)

Where:

  • userInput captures the string entered by the user.

Example

Go
package main import (     "fmt"     "strings" )  func main() {     // User input     var userInput string     fmt.Print("Enter string: ")     fmt.Scanln(&userInput)      // Converting to lower case     lowerInput := strings.ToLower(userInput)     fmt.Println("Lower case input:", lowerInput) } 

Output
Enter string: Lower case input:  

Conclusion

Converting a string to lower case in Go is straightforward using the strings.ToLower function. Whether working with a single string, multiple strings, or user input, the process remains simple and efficient.



Next Article
How to convert a string in lower case in Golang?

A

ankita_saini
Improve
Article Tags :
  • Go Language
  • Golang
  • Golang-String

Similar Reads

    How to convert a string in uppercase in Golang?
    In Go, strings are sequences of variable-width characters represented using UTF-8 Encoding. You can convert a string to uppercase using functions from the strings package, which must be imported into your program. In this article we will learn "How to Convert a String to Uppercase in Golang".Example
    2 min read
    How to Convert string to integer type in Golang?
    Strings in Golang 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 language, both signed and unsigned integers are available in four different sizes. In order to convert string to integer type in Golang, you can
    2 min read
    How to Get the String in Specified Base in Golang?
    Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides a FormatInt() function which is used to return the string representation of x in the given base, i.e., 2 <= base <= 36. Here, the resul
    2 min read
    How to Replace Characters in Golang String?
    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 strings, you are allowed to replace characters in the given string usin
    4 min read
    How to Reverse a String in Golang?
    Given a string and the task is to reverse the string. Here are a few examples. Approach 1: Reverse the string by swapping the letters, like first with last and second with second last and so on. Example: C // Golang program to reverse a string package main // importing fmt import "fmt" // function,
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences