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
+20.5k Golang : Convert seconds to minutes and remainder seconds
+6.2k Golang : Check if one string(rune) is permutation of another string(rune)
+25.3k Golang : Find files by extension
+6.1k Golang : A simple forex opportunities scanner
+5.4k Grep : How to grep for strings inside binary data
+4.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+5.8k Golang : Check if password length meet the requirement
+21.8k Golang : Gorilla mux routing example
+5.6k Golang : How to determine if request or crawl is from Google robots
+19.5k Golang : Convert PNG transparent background image to JPG or JPEG image
+26.9k Golang : Read, Write(Create) and Delete Cookie example
+11.3k Golang : How to display image file or expose CSS, JS files from localhost?