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
+10.4k Golang : Check a web page existence with HEAD request example
+7.2k Golang : How to solve "too many .rsrc sections" error?
+7.8k Android Studio : AlertDialog to get user attention example
+16.2k Golang : Get sub string example
+9k Golang : Sort lines of text example
+28k PHP : Count number of JSON items/objects
+10.1k Golang : Read file and convert content to string
+13.6k Golang : Generate Code128 barcode
+9.9k Golang : Qt get screen resolution and display on center example
+7.1k Golang : Fibonacci number generator examples
+8.1k Golang : Ways to recover memory during run time.