Slice string into letters

后端 未结 4 1721
予麋鹿
予麋鹿 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:41

    I think Split is what you're looking for:

    func Split(s, sep string) []string
    

    If sep is an empty string, it will split the string into single characters:

    Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators. If sep is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.

提交回复
热议问题