August 24, 2025
Go String Compare
Comparison of two strings in Go language is very easy task. Like integer values you can also compare string objects with the help of equal to operator (==) inside of if conditional statement. It is as easy as you are comparing two values. The example of string comparison mentioned below:
Code
package main
import "fmt"
# Go String Compare
func main() {
first_str := "Hello"
second_str := "Go Programmers"
if first_str == second_str {
fmt.Println('Strings are equal')
} else {
fmt.Println("Strings are not equal")
}
}
In above example, we have created two string parameters for comparison. We compare two string if strings are found equal then it shows message 'strings are equal' and returns true value. And if strings are not equal then it prints message that 'String are not equal.' and returns false.