Golang : Clean up null characters from input data
Problem :
You have input data in slice of bytes and you want to remove the null characters in the data. How to do that ?
Solution : Use the bytes.Trim()
function to remove the null characters from your input. Null character in byte format is \x00
and use this example :
withoutNull = bytes.Trim(withNull, "\x00")
References :
See also : Golang :Trim white spaces from a string
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
+4.6k Unix/Linux : How to pipe/save output of a command to file?
+6.1k Golang : How to get capacity of a slice or array?
+8.8k Golang : Gaussian blur on image and camera video feed examples
+10.7k Golang : Command line file upload program to server example
+9.2k Golang : Temperatures conversion example
+12.1k Golang : Print UTF-8 fonts on image example
+10.3k Golang : Generate random integer or float number
+30.1k Golang : How to verify uploaded file is image or allowed file types
+11.2k Use systeminfo to find out installed Windows Hotfix(s) or updates
+23.4k Golang : Check if element exist in map
+15.2k Golang : Delete certain files in a directory