Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.4k Golang : Exit, terminating or aborting a program
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+14.8k Golang : How to check if input from os.Args is integer?
+10.7k Golang : Detect user location with HTML5 geo-location
+8.6k Golang : How to check if a website is served via HTTPS
+5.9k Golang : Levenshtein distance example
+10.4k Golang : Surveillance with web camera and OpenCV
+15.1k Golang :Trim white spaces from a string
+35k Golang : Display float in 2 decimal points and rounding up or down
+5.2k Golang : Experimental emojis or emoticons icons programming language
+13.5k Golang : Rename directory
+8.2k Golang : Temperatures conversion example