strings.split golang example

Example 1: golang string split

s := strings.Split("a,b,c", ",")

Example 2: golang slice string

First of all, you should really read about strings, bytes and runes in Go.

And here is how you can achieve what you want: Go playground (I was not able to properly paste arabic symbols, but if Chinese works, arabic should work too).

    s := "abcdefghijklmnop" 
    fmt.Println(s[2:9]) 

    s = "something which is display"
    fmt.Println(string([]rune(s)[2:9]))

Example 3: golang split spaces

someString := "one    two   three four "

words := strings.Fields(someString)

fmt.Println(words, len(words)) // [one two three four] 4

Tags:

Misc Example