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
+41.1k Golang : How do I convert int to uint8?
+12k Golang : Encrypt and decrypt data with x509 crypto
+7.3k Gogland : Single File versus Go Application Run Configurations
+6.8k Web : How to see your website from different countries?
+15.9k Golang : Loop each day of the current month example
+10.8k Golang : Web routing/multiplex example
+6.4k Golang : When to use make or new?
+31.2k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+10.3k Golang : ISO8601 Duration Parser example
+11.8k Golang : Perform sanity checks on filename example
+34.7k Golang : Upload and download file to/from AWS S3
+9.8k Golang : Test a slice of integers for odd and even numbers