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
+6.8k Golang : How to fix html/template : "somefile" is undefined error?
+8.8k Golang : Generate EAN barcode
+5.4k Golang : Find change in a combination of coins example
+28.3k Golang : Record voice(audio) from microphone to .WAV file
+8.7k Golang : Apply Histogram Equalization to color images
+17.2k Golang : Parse date string and convert to dd-mm-yyyy format
+8.8k Golang : Generate Codabar
+4.2k Javascript : Detect when console is activated and do something about it
+6.6k Golang : constant 20013 overflows byte error message
+11.4k Golang : Find and draw contours with OpenCV example
+17.6k Golang : How to remove certain lines from a file
+7.7k Golang : Variadic function arguments sanity check example