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
+10.2k Generate Random number with math/rand in Go
+5.1k Javascript : Shuffle or randomize array example
+12.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+19.7k Swift : Convert (cast) Int to int32 or Uint32
+10.1k Golang : Meaning of omitempty in struct's field tag
+48.2k Golang : Upload file from web browser to server
+12.5k Golang : Convert int(year) to time.Time type
+8.7k Golang : How to capture return values from goroutines?
+3k Golang : Fix go-cron set time not working issue
+14.3k Golang : Missing Bazaar command
+23.7k Golang : Call function from another package
+9.2k Golang : Accessing content anonymously with Tor