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
+19.3k PHP : Convert(cast) int to double/float
+16.5k Golang : Aligning strings to right, left and center with fill example
+15.1k Golang : Test floating point numbers not-a-number and infinite example
+7.8k Golang : Get final balance from bit coin address example
+8.9k Golang : Convert octal value to string to deal with leading zero problem
+33.9k Golang : Get file last modified date and time
+7.1k Golang : Reverse text lines or flip line order example
+15.9k Golang : Check if IP address is version 4 or 6
+19.9k Golang : GORM create record or insert new record into database example
+4.5k Golang : Frobnicate or tweaking a string example
+7.9k Golang : Take screen shot of browser with JQuery example
+6.9k Golang : Load DSA public key from file example