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
+14k Golang : convert(cast) string to float value
+6k Golang : Launching your executable inside a console under Linux
+8.7k Linux/Unix : fatal: the Postfix mail system is already running
+6.7k Golang : Map within a map example
+5.9k Linux/Unix/PHP : Restart PHP-FPM
+9.2k Golang : How to use Gorilla webtoolkit context package properly
+8.4k Golang : Qt splash screen with delay example
+5.8k Unix/Linux/MacOSx : Get local IP address
+14.8k Android Studio : Use image as AlertDialog title with custom layout example
+18.1k Golang : How to make a file read only and set it to writable again?
+7.3k Golang : Array mapping with Interface