Testing for an undefined string in Go

This is an example Go program which illustrates testing for an undefined string.

package main

import (
        "fmt"
)

func main() {
        var s string
        var t string
        s = "bubba"
        if s == "" {
                fmt.Println("s is empty")
        }
        if t == "" {
                fmt.Println("t is empty")
        }
}

(download)

The output of the example looks like this:

t is empty

Web links


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer