Golang program to convert the specified string into title case

Here, we are going to learn how to convert the specified string into title case in Golang (Go Language)?
Submitted by Nidhi, on March 20, 2021 [Last updated : March 03, 2023]

Change the string into title case in Golang

Problem Solution:

In this program, we will create two strings, and convert the specified strings into title case using strings.Title(). After that, we will print updated string on the console screen.

Program/Source Code:

The source code to convert the specified string into title case is given below. The given program is compiled and executed successfully.

Golang code to change the specified string into title case

// Golang program to convert the specified string
// into title case

package main

import "fmt"
import "strings"

func main() {

	str1 := "hello how are you"
	str2 := "hii i am fine"

	fmt.Println(strings.Title(str1))
	fmt.Println(strings.Title(str2))
}

Output:

Hello How Are You
Hii I Am Fine

Explanation:

In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.

In the main() function, we created two string variables str1, str2. Then we used strings.Title() function to convert specified string into title case and print the result on the console screen.

Golang String Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.