Go: String comparison

Use == or != to check if two strings are equal:

if "Foo" == "Bar" {
        fmt.Println("Foo and Bar are equal.")
} else {
        fmt.Println("Foo and Bar aren't equal.")
}
// Output: Foo and Bar aren't equal.

Use <, >, <= or >= to determine the lexical order:

if "Foo" < "Bar" {
        fmt.Println("Foo comes before Bar.")
} else {
        fmt.Println("Foo doesn't come before Bar.")
}
// Output: Foo doesn't come before Bar.

Comments

Be the first to comment!