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
+6.7k Golang : How to convert strange string to JSON with json.MarshalIndent
+17.3k Golang : Get download file size
+13.5k Golang : Reset buffer example
+5.8k Nginx : Password protect a directory/folder
+10.4k Golang : How to pipe input data to executing child process?
+12.3k Facebook PHP getUser() returns 0
+9.7k Golang : Underscore string example
+10.7k Swift : Convert (cast) Float to String
+5.2k Linux/MacOSX : Search for files by filename and extension with find command
+12.6k Golang : Read XML elements data with xml.CharData example
+8.6k Golang : Changing a RGBA image number of channels with OpenCV
+10.9k Golang : Find and draw contours with OpenCV example