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