No startswith,endswith functions in Go?

后端 未结 2 842
攒了一身酷
攒了一身酷 2021-01-30 04:35

Just curious to findout: why aren\'t there standard functions like startswith, endswith, etc as part of the standard libraries in the Go programming language?

2条回答
  •  走了就别回头了
    2021-01-30 05:22

    The strings package contains HasPrefix and HasSuffix.

    import "strings"
    
    startsWith := strings.HasPrefix("prefix", "pre") // true
    endsWith := strings.HasSuffix("suffix", "fix") // true
    

    play.golang.org

提交回复
热议问题