Go language program to compare two strings are equal by ignoring the case


Following program shows you how to compare two strings are equal by ignoring the case.
In this program we get two different cases of strings from user and shows those strings are equal by using strings.EqualFold()

package main

import "fmt"
import "strings"

func main() {

  var string1 string 
  var string2 string
  fmt.Println("Please enter first string:")
  fmt.Scanf("%s", &string1)
  fmt.Println("Please enter second string:")
  fmt.Scanf("%s", &string2)
  if (strings.EqualFold(string1,string2)) {
  fmt.Println("Given strings are equal")
  } else {
    fmt.Println("Given strings are not equal")
  }
}

Output:

Example1:

Please enter first string:
 HELLO
Please enter second string:
 hello
Given strings are equal

Example2:

Please enter first string:
 hello
Please enter second string:
 world
Given strings are not equal