Last active
August 29, 2015 14:27
-
-
Save 178inaba/7a9834505f17af1c9671 to your computer and use it in GitHub Desktop.
delete element of slice of go
This file contains hidden or 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 "fmt" | |
func main() { | |
s := []string{"abc"} | |
s = append(s, "def") | |
// delete | |
s = append(s[:1], s[1+1:]...) | |
fmt.Println("len:", len(s), "cap:", cap(s)) | |
} |
This file contains hidden or 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
$ go run del_slice.go | |
len: 1 cap: 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment