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
+17.8k Golang : Qt image viewer example
+6.1k Golang : Extract XML attribute data with attr field tag example
+17.6k Golang : Upload/Receive file progress indicator
+35.2k Golang : Strip slashes from string example
+5.3k Golang : What is StructTag and how to get StructTag's value?
+7.7k Golang : How to execute code at certain day, hour and minute?
+14.5k How to automatically restart your crashed Golang server
+11.9k Golang : Determine if time variables have same calendar day
+5.9k Linux/MacOSX : Search for files by filename and extension with find command
+12.6k Golang : Pass database connection to function called from another package and HTTP Handler
+8.7k Golang : Random integer with rand.Seed() within a given range
+11.4k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions