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.7k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+6.8k Golang : How to call function inside template with template.FuncMap
+7.1k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+7k CloudFlare : Another way to get visitor's real IP address
+28.3k Golang : Read, Write(Create) and Delete Cookie example
+10.4k Golang : Select region of interest with mouse click and crop from image
+24.3k Golang : GORM read from database example
+32.5k Golang : Regular Expression for alphanumeric and underscore
+22.5k Golang : Set and Get HTTP request headers example
+26.2k Golang : Calculate future date with time.Add() function
+9.1k Golang : Temperatures conversion example
+9.5k Golang : Sort and reverse sort a slice of floats