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
+39.7k Golang : UDP client server read write example
+7.2k Android Studio : How to detect camera, activate and capture example
+26.4k Golang : Encrypt and decrypt data with AES crypto
+10.9k Golang : Web routing/multiplex example
+23.8k Golang : Upload to S3 with official aws-sdk-go package
+7.1k Golang : File system scanning
+13.8k Golang : concatenate(combine) strings
+18.9k Golang : Calculate entire request body length during run time
+17.7k Golang : How to log each HTTP request to your web server?
+11.1k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+13.1k Golang : Linear algebra and matrix calculation example
+11.4k Golang : Fuzzy string search or approximate string matching example