溫馨提示×

go語言if語句怎樣判斷字符串

小樊
95
2024-12-06 06:48:56
欄目: 編程語言

在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、str2str3。然后,我們使用if語句和==操作符來比較這些字符串是否相等,并輸出相應的結果。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女