RosettaCodeData/Task/Empty-string/Go/empty-string-2.go

24 lines
391 B
Go
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
package main
import (
2026-02-01 16:33:20 -08:00
"fmt"
2023-07-01 11:58:00 -04:00
)
func test(s string) {
2026-02-01 16:33:20 -08:00
if len(s) == 0 {
fmt.Println("empty")
} else {
fmt.Println("not empty")
}
2023-07-01 11:58:00 -04:00
}
func main() {
2026-02-01 16:33:20 -08:00
// assign an empty string to a variable.
str1 := ""
str2 := " "
// check if a string is empty.
test(str1) // prt empty
// check that a string is not empty.
test(str2) // prt not empty
2023-07-01 11:58:00 -04:00
}