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
+19.9k Golang : Convert string slice to struct and access with reflect example
+8.9k Golang : Setting variable value with ldflags
+18.2k Golang : Convert seconds to human readable time format example
+18.4k Swift : Convert (cast) Int to int32 or Uint32
+4k Fix Google Analytics Redundant Hostnames problem
+32.8k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+20.2k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+16.4k How to enable MariaDB/MySQL logs ?
+13.2k Golang : Reset buffer example
+8.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+7.3k Golang : How to check variable or object type during runtime?
+15.7k Golang : How to tell if a file is compressed either gzip or zip ?