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
+3.6k PHP : Extract part of a string starting from the middle
+8.3k Golang : Print how to use flag for your application example
+28k Golang : Get local IP and MAC address
+4.4k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+17.9k Golang : Read directory content with os.Open
+8.3k Golang : Convert octal value to string to deal with leading zero problem
+19.5k Golang : Read a file into an array or slice example
+12.1k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+19.3k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+10.7k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+26.7k Golang : Save map/struct to JSON or XML file