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
+6k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+6.2k Golang : Dealing with struct's private part
+8.7k PHP : Get coordinates latitude/longitude from string
+4.1k Swift : Convert (cast) Float to Int or Int32 value
+6.3k Golang : Getting Echo framework StartAutoTLS to work
+27.8k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+8.4k Golang : How to protect your source code from client, hosting company or hacker?
+6.6k Golang : How to execute code at certain day, hour and minute?
+17.8k Golang : How to get own program name during runtime ?
+10.9k Android Studio : Highlight ImageButton when pressed on example
+34.9k Golang : Display float in 2 decimal points and rounding up or down
+5.5k Golang : Spell checking with ispell example