在Go語言中,你可以使用if語句和==操作符來判斷一個字符串是否等于另一個字符串。以下是一個簡單的示例:
package main
import "fmt"
func main() {
str1 := "Hello, World!"
str2 := "Hello, World!"
str3 := "Go is awesome!"
if str1 == str2 {
fmt.Println("str1 and str2 are equal")
} else {
fmt.Println("str1 and str2 are not equal")
}
if str1 == str3 {
fmt.Println("str1 and str3 are equal")
} else {
fmt.Println("str1 and str3 are not equal")
}
}
在這個示例中,我們首先定義了三個字符串變量str1、str2和str3。然后,我們使用if語句和==操作符來比較這些字符串是否相等,并輸出相應的結果。