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
+12.2k Golang : Find and draw contours with OpenCV example
+24.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+20.8k Golang : Saving private and public key to files
+15.4k Golang : How to get Unix file descriptor for console and file
+9.2k Golang : Handle sub domain with Gin
+9.6k Mac OSX : Get a process/daemon status information
+15.7k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+5.2k Golang : Display packages names during compilation
+30k Golang : Get and Set User-Agent examples
+5.5k Javascript : How to loop over and parse JSON data?
+5.9k Golang : List all packages and search for certain package
+18.6k Golang : Aligning strings to right, left and center with fill example