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
+14.2k Golang : Reverse IP address for reverse DNS lookup example
+5.9k Golang : List all packages and search for certain package
+10.7k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+7.6k Golang : Gorrila set route name and get the current route name
+17.1k Golang : How to save log messages to file?
+11.4k Golang : How to use if, eq and print properly in html template
+9.4k Golang : How to control fmt or log print format?
+16.6k Golang : Convert slice to array
+9k Golang : GMail API create and send draft with simple upload attachment example
+9k Golang : Gaussian blur on image and camera video feed examples
+9.6k Facebook : Getting the friends list with PHP return JSON format
+9k Golang : Sort lines of text example