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
+21.5k Golang : Test file read write permission example
+12.6k Golang : Reverse IP address for reverse DNS lookup example
+16.1k Golang : delete and modify XML file content
+6.4k Golang : Scanf function weird error in Windows
+7.6k Golang : Progress bar with ∎ character
+81.8k Golang : How to convert character to ASCII and back
+7.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+4.3k Golang : Pad file extension automagically
+6.3k Golang : Gorrila mux.Vars() function example
+32.7k Golang : Proper way to set function argument default value
+9.3k Generate Random number with math/rand in Go