Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created May 28, 2019 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/90d6135fa1784d53b84f7f647b21d1c6 to your computer and use it in GitHub Desktop.
Save miguelmota/90d6135fa1784d53b84f7f647b21d1c6 to your computer and use it in GitHub Desktop.
Golang trim control characters (NULL) from bytes slice
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