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
+12.6k Golang : http.Get example
+7.3k Golang : Handling Yes No Quit query input
+8.9k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+13.9k Golang : Check if a file exist or not
+7.3k Golang : Rot13 and Rot5 algorithms example
+14.9k Golang : Accurate and reliable decimal calculations
+29.5k Golang : Get time.Duration in year, month, week or day
+23.7k Golang : Upload to S3 with official aws-sdk-go package
+10.1k Golang : Convert file unix timestamp to UTC time example
+16.6k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+33.7k Golang : Create x509 certificate, private and public keys
+15.8k Golang : Generate universally unique identifier(UUID) example