Menu Close

Go – How to compare two strings without case sensitive in go golang ?

Here, We are going to learn about comparing two strings without case sensitive in go golang. We can do that by using EqualFold() function of strings package in go golang.

Function prototype:

func EqualFold(str_1 string, str_2 string) bool

Return value:

if both the strings are equal then It returns ‘true’ else ‘false’.

EqualFold() function returns whether str_1 and str_2, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

Example:

package main

import (
	"fmt"
	"strings"
)

func main() {

	fmt.Println(strings.EqualFold("Go", "go"))

	fmt.Println(strings.EqualFold("Go", "lang"))

}

Output:

true
false

To learn more about golang, Please refer given below link.

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, packages, strings

Leave a Reply

Your email address will not be published. Required fields are marked *