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
+6.4k Golang : Derive cryptographic key from passwords with Argon2
+5.3k Golang : Stop goroutine without channel
+12.9k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+13k Golang : Linear algebra and matrix calculation example
+11k Golang : How to use if, eq and print properly in html template
+9.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+37k Upload multiple files with Go
+25.7k Mac/Linux and Golang : Fix bind: address already in use error
+10.2k Golang : Meaning of omitempty in struct's field tag
+12k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+7.9k Golang : Routes multiplexer routing example with regular expression control
+7.9k Golang : Add build version and other information in executables