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
+21.4k Golang : Get password from console input without echo or masked
+8.2k Golang : Handle Palindrome string with case sensitivity and unicode
+7.7k Gogland : Single File versus Go Application Run Configurations
+8.4k Golang : HttpRouter multiplexer routing example
+6k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+12.1k Golang : How to parse plain email text and process email header?
+5.4k Python : Convert(cast) string to bytes example
+12.7k Golang : HTTP response JSON encoded data
+14.8k Android Studio : Use image as AlertDialog title with custom layout example
+19k Golang : Delete duplicate items from a slice/array
+9.3k Golang : Serving HTTP and Websocket from different ports in a program example
+12.5k Golang : Get month name from date example