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
+9.4k Golang : Get all countries currencies code in JSON format
+22.5k Generate checksum for a file in Go
+15.5k Golang : ROT47 (Caesar cipher by 47 characters) example
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+21.7k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+5.2k Golang : Calculate half life decay example
+16.3k Golang : Find out mime type from bytes in buffer
+8.3k Golang: Prevent over writing file with md5 hash
+7.7k Golang : Reverse a string with unicode
+15.5k Golang : How to convert(cast) IP address to string?
+9.6k Golang : Populate slice with sequential integers example
+22.9k Golang : Test file read write permission example