Golang: Cut Slice (Delete Elements)
Cut Slice (Delete Elements)
Use append
to delete elements, like this:
append(s[:i], s[j:]...)
-
Delete from index i to j.
package main import "fmt" func main() { var x = []byte("0123456") x = append(x[:3], x[5:]...) fmt.Printf("%s\n", x) // 1236 }
Golang, array and slice
- Golang: Array
- Golang: Slice
- Golang: Slice of Slice
- Golang: Append to Slice
- Golang: Cut Slice (Delete Elements)
- Golang: Copy Slice
- Golang: Clear Slice
- Golang: Nested Slice
- Golang: Slice of Strings to String
- Golang: Iterate Slice
- Golang: Convert Value to String
- Golang: Convert Array to Slice
- Golang: Print Slice, Array