Golang program to match two same strings in different cases

Here, we are going to learn how to match two same strings in different cases in Golang (Go Language)?
Submitted by Nidhi, on March 18, 2021 [Last updated : March 03, 2023]

Matching two same strings in different cases in Golang

Problem Solution:

In this program, we will check the two same strings in different cases using EqualFold() function. The EqualFold() function returns a Boolean value to the calling function.

Program/Source Code:

The source code to check the two same strings in different cases is given below. The given program is compiled and executed successfully.

Golang code to match two same strings in different cases

// Golang program to check same string
// in different cases

package main

import "fmt"
import "strings"

func main() {
	str1 := "INDIA"
	str2 := "india"
	str3 := "India"

	fmt.Println(strings.EqualFold(str1, str1))
	fmt.Println(strings.EqualFold(str1, str2))
	fmt.Println(strings.EqualFold(str1, str3))
}

Output:

true
true
true

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 three string variables str1, str2, str3. After that, we checked the equality of two strings with the different cases using EqualFold() function and print the Boolean value on the console screen.

Golang String Programs »



Related Programs




Comments and Discussions!

Load comments ↻






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