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
+18.3k Golang : Check if os.Stdin input data is piped or from terminal
+29.2k Golang : How to redirect to new page with net/http?
+5.5k Golang : Find the longest line of text example
+9.7k PHP : Convert(cast) bigInt to string
+29.9k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+15.2k Golang : Convert slice to array
+19.8k Golang : Get password from console input without echo or masked
+3.6k Linux/MacOSX : Search and delete files by extension
+6.7k Gogland : Where to put source code files in package directory for rookie
+15.4k Golang : File path independent of Operating System
+6.5k Golang : Gorrila set route name and get the current route name
+9.5k Golang : Fix go.exe is not compatible with the version of Windows you're running