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
+14k Generate salted password with OpenSSL example
+3.7k Java : Get FX sentiment from website example
+6.2k Golang : Grab news article text and use NLP to get each paragraph's sentences
+5.9k Golang : Markov chains to predict probability of next state example
+11.4k Golang : Post data with url.Values{}
+19.7k Golang : Close channel after ticker stopped example
+10.2k Golang : Edge detection with Sobel method
+9.3k Golang : does not implement flag.Value (missing Set method)
+7.8k Golang : How to execute code at certain day, hour and minute?
+7.5k Golang : Process json data with Jason package
+15.5k Golang : invalid character ',' looking for beginning of value