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
+5.9k Javascript : Get operating system and browser information
+10.7k PHP : Convert(cast) bigInt to string
+31.3k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+7.2k Linux : How to fix Brother HL-1110 printing blank page problem
+39k Golang : How to read CSV file
+6.8k Nginx : Password protect a directory/folder
+9.1k Golang : Generate Codabar
+13.3k Golang : Get constant name from value
+4.6k Facebook : How to place save to Facebook button on your website
+8.2k Golang : Number guessing game with user input verification example
+15.4k Golang : How to convert(cast) IP address to string?