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
+7.3k Swift : Convert (cast) Character to Integer?
+10.3k Golang : Generate DSA private, public key and PEM files example
+15.4k Golang : read gzipped http response
+4.8k Golang : Error handling methods
+4.9k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+17.1k Golang : Implement getters and setters
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+5.9k Golang : Calculate BMI and risk category
+26.6k Golang : Change a file last modified date and time
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+7.9k Golang : How to use Gorilla webtoolkit context package properly
+14.4k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content