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
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+7.4k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+6.8k Golang : Calculate pivot points for a cross
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+7.7k Golang : Mapping Iban to Dunging alphabets
+29.6k Golang : Saving(serializing) and reading file with GOB
+16.1k Golang : How to reverse elements order in map ?
+11k Golang : Replace a parameter's value inside a configuration file example
+25.3k Golang : Convert uint value to string type
+11.3k Golang : Intercept and process UNIX signals example
+9.4k Golang : Create unique title slugs example
+5.5k Clean up Visual Studio For Mac installation failed disk full problem