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.3k Golang : Send email with attachment
+5.1k PHP : How to check if an array is empty ?
+48.9k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+5.7k Unix/Linux : How to get own IP address ?
+8.2k Golang : Play .WAV file from command line
+10.1k Google Maps URL parameters configuration
+25.1k Golang : Convert file content into array of bytes
+21.3k Golang : Set and Get HTTP request headers example
+2.9k Java : Random alphabets, alpha-numeric or numbers only string generator
+6.5k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+3.7k Linux/MacOSX : Search and delete files by extension