Slice string into letters

后端 未结 4 1735
予麋鹿
予麋鹿 2021-02-01 19:19

How to slice one string in Go language into array of string letters it contains?

For example, turn string \"abc\" into array \"a\", \"b\", \"c\".

4条回答
  •  时光取名叫无心
    2021-02-01 19:56

    Use strings.Split on it:

    package main
    
    import (
        "fmt"
        "strings"
    )
    
    func main() {
        fmt.Printf("%#v\n",strings.Split("abc", ""))
    }
    

    http://play.golang.org/p/1tNfu0iyHS

提交回复
热议问题