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
+22.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+4.1k Golang : Constant and variable names in native language
+19.8k Golang : Sort and reverse sort a slice of strings
+6.7k Golang : Ways to recover memory during run time.
+17.6k Golang : Get host name or domain name from IP address
+9.8k Golang : Removes punctuation or defined delimiter from the user's input
+5k Golang : How to write backslash in string?
+44.1k Golang : Read tab delimited file with encoding/csv package
+11k Golang : List running EC2 instances and descriptions
+4.6k Unix/Linux : How to find out the hard disk size?
+21k Golang : Repeat a character by multiple of x factor
+7.4k Golang : Implementing class(object-oriented programming style)