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
+5.1k PageSpeed : Clear or flush cache on web server
+15.4k Golang : How to implement two-factor authentication?
+17.6k Golang : Get host name or domain name from IP address
+10k Golang : Create S3 bucket with official aws-sdk-go package
+10.6k CodeIgniter : Import Linkedin data
+6.5k Golang : Detect sample rate, channels or latency with PortAudio
+8.9k Golang : Find and replace data in all files recursively
+14.1k Golang : Get query string value on a POST request
+6.2k Golang : Use modern ciphers only in secure connection
+5.8k How to let Facebook Login button redirect to a particular URL ?
+21.2k Golang : Convert Unix timestamp to UTC timestamp
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator