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
+22.1k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+18.1k Golang : Simple client server example
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+36.2k Golang : Get file last modified date and time
+7.2k Nginx : How to block user agent ?
+7.5k Golang : Example of custom handler for Gorilla's Path usage.
+7.6k Golang : Detect sample rate, channels or latency with PortAudio
+10.7k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+19.4k Golang : Calculate entire request body length during run time
+6.6k Golang : Calculate diameter, circumference, area, sphere surface and volume
+14.1k Golang : Google Drive API upload and rename example
+15.4k Golang : Delete certain files in a directory