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
+52.1k Golang : How to get struct field and value by name
+6.6k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+9.5k Golang : Find correlation coefficient example
+17.2k Golang : Check if IP address is version 4 or 6
+30k Golang : How to verify uploaded file is image or allowed file types
+13.1k Golang : Verify token from Google Authenticator App
+12.5k Golang : zlib compress file example
+5.8k Golang : Experimenting with the Rejang script
+9.5k Golang : Qt get screen resolution and display on center example
+6.8k Golang : Levenshtein distance example
+10.3k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+23.3k Golang : Check if element exist in map