
go
xiangjie256
这个作者很懒,什么都没留下…
展开
-
hello go
[code="go"]package mainimport ( "fmt" "os" "strings")func main() { who := "World" if len(os.Args) > 1 { who = strings.Join(os.Args[1:], " ") } arr := []string{&qu原创 2017-06-24 11:06:28 · 94 阅读 · 0 评论 -
go 指针
[code="go"]package mainimport "fmt"func f(s *string) (string, string) { *s = "def" return "hello", *s}func main() { s := "abc" a, b := f(&s) fmt.Println(a, b)}hello def..原创 2017-07-09 10:12:14 · 89 阅读 · 0 评论 -
go 正则
[code="go"]package mainimport "fmt"import "regexp"func main() { //一个字符串是否符合一个表达式。 match, _ := regexp.MatchString("([1-9]+)", "123fdsa") fmt.Println(match) r, _ := regexp.Compile("(.原创 2017-07-08 10:38:16 · 87 阅读 · 0 评论 -
go字符串处理
[code="go"]package mainimport "fmt"import "strings"import "strconv"func main() { a := "aaa,111,222" arr := strings.Split(a, ",") fmt.Println(arr[1:]) b := " ccc &原创 2017-07-06 22:23:29 · 94 阅读 · 0 评论 -
go 格式化输出
[code="go"]package mainimport "fmt"func main() { fmt.Println(1, 2, "abc:%t", true) fmt.Printf("format print:%s %t\n", "aaa", true)}1 2 abc:%t trueformat print:aaa true[/code]原创 2017-07-05 21:59:30 · 98 阅读 · 0 评论 -
go结构体
[code="go"]package mainimport "fmt"type s struct { i int j float64}func main() { var s1 s s1.i = 1 s1.j = 1.5 fmt.Println(s1.i, s1.j)}1 1.5[/code]原创 2017-07-02 11:14:19 · 106 阅读 · 0 评论 -
go基本数据类型
[code="go"]package mainimport "fmt"import "math"func main() { const i = 1 f := 1.2 fmt.Println("a", i, f) a := "aaa" b := "bbb" c := a + b var d []string var e = append原创 2017-07-01 10:11:35 · 116 阅读 · 0 评论 -
go chan
go func()中的内容如果没有sleep,主线程不保证能执行完[code="go"]package mainimport ( "fmt" "time")func main() { msg := make(chan string, 10) msg2 := make(chan string, 5) go func() { msg ...原创 2017-06-29 21:25:23 · 102 阅读 · 0 评论 -
go 切片
[code="go"]package mainimport "fmt"func main() { //创建一个初始元素个数为5的数组切片,元素初始值为0,并预留10个元素的存储空间 a := make([]int, 5, 10) a[1] = 1 fmt.Println(len(a), cap(a), a) b := []string{"a", "b",...原创 2017-06-28 22:02:21 · 94 阅读 · 0 评论 -
go 读写文件
[code="go"]package mainimport ( "bufio" "fmt" "io" "os")func check(e error) { if e != nil { panic(e) }}func write_file(file_name string) { f, err := os.Create(file_n...原创 2017-06-27 22:24:08 · 135 阅读 · 0 评论 -
go 循环
[code="go"]package mainimport ( "fmt")func main() { for i := 1; i原创 2017-06-25 11:06:13 · 93 阅读 · 0 评论 -
go json使用
[code="go"]package mainimport ( "encoding/json" "fmt")type DateValue map[string]stringtype A struct { Str string IntVal int Str_vec []string Time string `json:"time...原创 2017-08-04 11:48:20 · 131 阅读 · 0 评论