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
+14.7k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+4.3k Golang : Issue HTTP commands to server and port example
+23.5k Golang : Get current file path of a file or executable
+5.1k Golang : Create new color from command line parameters
+6k Golang : Squaring elements in array
+18k Golang : Convert seconds to human readable time format example
+18.1k Golang : Example for DSA(Digital Signature Algorithm) package functions
+28.6k Golang : Remove characters from string example
+6.2k Golang : Dealing with postal or zip code example
+9.4k Swift : Convert (cast) String to Integer
+10.2k Golang : Simple file scaning and remove virus example