In Go, you can compare two strings using the ==
operator for equality check.
In this example,
str1
and str2
with different values.==
operator.==
operator returns true
if the strings are equal, and false
otherwise.// Comparison of Strings in Go
package main
import "fmt"
func main() {
str1 := "Hello"
str2 := "hello"
result := str1 == str2
fmt.Println("Strings are equal:", result)
}
Strings are equal: false
In this tutorial, we learned How to Compare Two Strings in Go language with well detailed examples.