引用部分:
import (
"bufio"
"flag"
"log"
"strings"
)
自定义字符串:
var myString = "add -a=123 -b=456"
func main(){
var a,b int
var add = flag.NewFlagSet("add", flag.ContinueOnError)
add.IntVar(&a,"a",0,"value a")
add.IntVar(&b,"b",1,"value b")
cmd := strings.Fields(myString)
add.Parse(cmd[1:])
log.Println(a+b)
}
是不是很简单
有疑问加站长微信联系(非本文作者)