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
+13k Python : Convert IPv6 address to decimal and back to IPv6
+8.4k Golang: Prevent over writing file with md5 hash
+9.6k Android Studio : Indicate progression with ProgressBar example
+10.8k Golang : Get currencies exchange rates example
+11.8k How to tell if a binary(executable) file or web application is built with Golang?
+6.6k Elasticsearch : Shutdown a local node
+14.1k Golang : Human readable time elapsed format such as 5 days ago
+13.6k Golang : Get constant name from value
+7.2k Golang : Get Alexa ranking data example
+21.2k Golang : For loop continue,break and range
+4.8k JavaScript: Add marker function on Google Map