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
+10.7k Golang : Save webcamera frames to video file
+25.1k Golang : Find files by extension
+4.8k Golang : Find change in a combination of coins example
+4.7k Unix/Linux : How to open tar.gz file ?
+8.8k Golang : Compare files modify date example
+3.1k Detect if Google Analytics and Developer Media are loaded properly or not
+9.8k Android Studio : Create custom icons for your application example
+8.5k Golang : Turn string or text file into slice example
+4.5k Swift : Convert string array to array example
+12.7k Golang : How to check if your program is running in a terminal
+7.7k Golang : Simple histogram example
+8.1k Golang : Extract or copy items from map based on value