How to slice a string using a delimiter

醉酒当歌 提交于 2019-12-12 08:17:27

问题


In Go, if I have a string variable s:

var s string = "a,b,c,d,e"

How can I convert or split or explode it into a slice or an array of strings so that it will become:

arr[0] = "a"
...
arr[4] = "e"

回答1:


You should use the strings package for that.

stringSlice := strings.Split(s, ",")

http://play.golang.org/p/UKZbcuJUPP



来源:https://stackoverflow.com/questions/14263733/how-to-slice-a-string-using-a-delimiter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!