Golang : How to check for empty array string or string?
Sometimes that most obvious thing can be the hardest to remember. Putting this down as a note for myself and maybe useful to you too.
Problem :
Need to check if a string or []string is empty. How to do that?
Solutions :
if str is a string
len(strings.TrimSpace(str)) == 0
and let say str is an array []string
var str []string
strings.TrimSpace(strings.Join(str, "")) == ""
Reference :
https://groups.google.com/forum/#!topic/golang-nuts/7Ks1iq2s7FA
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+21.4k Golang : Create and resolve(read) symbolic links
+8.5k Golang : Ackermann function example
+6k AWS S3 : Prevent Hotlinking policy
+12.4k Golang : Get remaining text such as id or filename after last segment in URL path
+5.5k How to check with curl if my website or the asset is gzipped ?
+10.2k Golang : Identifying Golang HTTP client request
+43.4k Golang : Convert []byte to image
+5.8k List of Golang XML tutorials
+4.9k Javascript : How to get width and height of a div?
+8.4k Golang : Implementing class(object-oriented programming style)
+10.9k Golang : Command line file upload program to server example