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
+18.2k Golang : Example for RSA package functions
+4.2k Linux/MacOSX : Search and delete files by extension
+5.1k Unix/Linux/MacOSx : How to remove an environment variable ?
+14.1k Golang : How to filter a map's elements for faster lookup
+18.1k Golang : How to get hour, minute, second from time?
+22.1k Golang : How to read JPG(JPEG), GIF and PNG files ?
+9k Golang : Generate random Chinese, Japanese, Korean and other runes
+5.5k Fix yum-complete-transaction error
+17.1k Golang : Get future or past hours, minutes or seconds
+12k Golang : How to check if a string starts or ends with certain characters or words?
+6.3k Golang : Totalize or add-up an array or slice example
+12.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath