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
+20.2k Golang : Pipe output from one os.Exec(shell command) to another command
+16.1k Golang :Trim white spaces from a string
+12.7k Golang : Get terminal width and height example
+20.9k Golang : How to get time zone and load different time zone?
+16.4k Golang : Gzip file example
+10.4k Android Studio : Checkbox for user to select options example
+8.4k Golang : How to join strings?
+14k Golang : How to pass map to html template and access the map's elements
+10.6k Golang : Removes punctuation or defined delimiter from the user's input
+6.3k Golang : Totalize or add-up an array or slice example
+5.3k Python : Print unicode escape characters and string
+6.2k PHP : Proper way to get UTF-8 character or string length