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.8k Golang : Bubble sort example
+17k Golang : For loop continue,break and range
+33.6k Golang : Convert(cast) int64 to string
+4.2k Golang : Humanize and Titleize functions
+3.9k Golang : Debug with Godebug
+22.4k Golang : Detect (OS) Operating System
+6.5k PHP : Get coordinates latitude/longitude from string
+5.8k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+4.8k Golang : Gorrila set route name and get the current route name
+3.9k Fix fatal error: evacuation not done in time problem
+6.1k Golang : Get all countries currencies code in JSON format
+10.3k Golang : Submit web forms without browser by http.PostForm example