Jump to content
新域网络技术论坛

Search the Community

Showing results for tags 'go'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 论坛服务
    • 公告栏
  • 技术讨论
    • IPB相关讨论
    • PHP技术探讨
    • FREEBSD讨论
    • 其它技术
    • 软件分享
  • 业余无线电
    • 使用指南
    • 设备讨论

Blogs

There are no results to display.

Product Groups

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


位置


兴趣


呼号

Found 1 result

  1. package main import ( "./myfunc" //加载本项目包 "flag" //解析命令行参数 "fmt" "os" "strconv" ) //定义解析的命令行参数 var s = flag.String("s", "", "某某字符串") var b = flag.Bool("b", false, "布尔参数") func main() { //定义names变量 等同于 names := "World" var names = "World" //遍历命令行参数并输出 for idx, args := range os.Args { fmt.Println(strconv.Itoa(idx) + ":", args) } //解析命令行参数并赋值 flag.Parse() fmt.Println("-b:", *b) fmt.Println("-s:", *s) //未解析的参数 var params = flag.Args() fmt.Println(params) //如果有未解析的参数,访问 if len(params) > 0 { names = params[0] } fmt.Println("Hello " + names + "!") //多数据定义并赋值 var a, b = 2, 3 //省略var的方式定义,如果之前已经有此变量时会产生编译错误 c := 99 fmt.Printf("%d _++_+ %d, %x\n", a, b, &c) // & 取地址 * 取内容 fmt.Println(*&c) //调用其他包的函数 fmt.Println(myfunc.Demo("Hello", "=-=-=", "World!")) //字典定义以及遍历 dict := map[string] string {"One": "1111", "Two": "2222", "Three": "3333",} for k, v := range dict { fmt.Printf("%s: %s\n", k, v) } } /* 文件名及路径:myfunc/functions.go */ package myfunc func Demo(sstr ...string) string { result := "" //数组遍历方式 /*for i := 0; i < len(sstr); i ++ { result += " " + sstr[i] }*/ //通用遍历方式 数组、切片、字典通用 for _, v := range sstr { result += " " + v } return result }
×
×
  • Create New...