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
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+11.3k Golang : Byte format example
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+17k Golang : How to save log messages to file?
+9.3k Golang : Temperatures conversion example
+19.3k Golang : Get RGBA values of each image pixel
+5.9k Golang : Denco multiplexer example
+27.2k Golang : Find files by name - cross platform example
+6.4k Golang : How to search a list of records or data structures
+29.9k Golang : How to get HTTP request header information?
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+13.2k Golang : Convert(cast) int to int64