How to check if a string is empty or only whitespace in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	var str string = "   "
	
	if strings.TrimSpace(str) == "" {
        fmt.Println("String is empty or only whitespace")
    }
}



/*
run:

String is empty or only whitespace

*/

 



answered Nov 7, 2024 by avibootz
...