删除切片中未分配的(零值)

How to delete all zero values or unassigned values?

Here a stack trace is put into a slice.. How can all the unassigned (zero values) be deleted?

Is there some fancy function to slice a slice.. Something like substring of a string

trace := make([]byte, 1024)
runtime.Stack(trace, true)

Use a slice expression to trim the unused portion of the stack buffer. The Stack function conveniently returns the number of bytes written to the buffer.

    trace := make([]byte, 1024)
    n := runtime.Stack(trace, true)
    trace = trace[:n]

playground link