How to split a string and assign it to variables

前端 未结 9 1585
无人及你
无人及你 2020-12-07 10:27

In Python it is possible to split a string and assign it to variables:

ip, port = \'127.0.0.1:5432\'.split(\':\')

but in Go it does not see

9条回答
  •  时光说笑
    2020-12-07 11:08

    As a side note, you can include the separators while splitting the string in Go. To do so, use strings.SplitAfter as in the example below.

    package main
    
    import (
        "fmt"
        "strings"
    )
    
    func main() {
        fmt.Printf("%q\n", strings.SplitAfter("z,o,r,r,o", ","))
    }
    

提交回复
热议问题