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
+10.1k Golang : Natural string sorting example
+5.1k Golang : List all packages and search for certain package
+13.8k Golang : Save(pipe) HTTP response into a file
+17.1k Golang : Convert IPv4 address to decimal number(base 10) or integer
+6.1k Fix sudo yum hang problem with no output or error messages
+14.1k Golang : Get HTTP protocol version example
+33.5k Golang : Integer is between a range
+7.4k Golang : Auto-generate reply email with text/template package
+16.6k Golang : [json: cannot unmarshal object into Go value of type]
+8.8k Golang : Eroding and dilating image with OpenCV example
+14.5k Golang : Get digits from integer before and after given position example
+22.3k Find and replace a character in a string in Go