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
+17k Golang : How to generate QR codes?
+6.6k Golang : Calculate diameter, circumference, area, sphere surface and volume
+10k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+16.8k Golang : Gzip file example
+7.5k Golang : Gorrila set route name and get the current route name
+5.5k Golang *File points to a file or directory ?
+5.9k Golang : Launching your executable inside a console under Linux
+20.8k Golang : Secure(TLS) connection between server and client
+5.9k Javascript : How to replace HTML inside <div>?
+25.3k Golang : Storing cookies in http.CookieJar example
+19.5k Golang : Fix cannot download, $GOPATH not set error
+5.5k Golang : Get S3 or CloudFront object or file information