Created
October 9, 2013 05:46
-
-
Save sunzhongwei/6896747 to your computer and use it in GitHub Desktop.
Golang slice usage
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" | |
"io/ioutil" | |
"net/http" | |
) | |
func fetch_web_page() { | |
rsp, _ := http.Get("http://www.sunzhongwei.com") | |
html, _ := ioutil.ReadAll(rsp.Body) | |
new_html := string(html) | |
fmt.Println(new_html) | |
} | |
func slice_usage() { | |
sl := []int{} | |
sl = append(sl, 1) | |
sl = append(sl, 56) | |
fmt.Println(sl) | |
sl2 := []string{} | |
sl2 = append(sl2, "zhongwei") | |
sl2 = append(sl2, "test") | |
sl2 = append(sl2, "1", "2", "3") | |
fmt.Println(sl2) | |
fmt.Println("capacity of sl2 is:", cap(sl2)) | |
fmt.Println("length of sl2 is:", len(sl2)) | |
} | |
func main() { | |
fmt.Println("Start ...") | |
slice_usage() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment