Created
May 28, 2019 07:29
-
-
Save miguelmota/90d6135fa1784d53b84f7f647b21d1c6 to your computer and use it in GitHub Desktop.
Golang trim control characters (NULL) from bytes slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
b := make([]byte, 100) | |
b[0] = 'A' | |
fmt.Println(len(b)) // 100 | |
b = bytes.Trim(b, "\x00") | |
fmt.Println(len(b)) // 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment