Golang bytes.Split() function example
package bytes
Split slices the given input into all subslices separated by a separator(2nd parameter) and returns a slice of the subslices between those separators. If separator parameter is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.
Golang bytes.Split() function usage example
package main
import (
"fmt"
"bytes"
)
func main() {
str := []byte("I LOVE THIS WORLD!")
for i, rune := range bytes.Split(str, []byte{' '}) { //split by white space
fmt.Printf("Counter %d : %s\n", i , string(rune))
}
}
Output :
Counter 0 : I
Counter 1 : LOVE
Counter 2 : THIS
Counter 3 : WORLD!
Reference :
Advertisement
Something interesting
Tutorials
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+11.9k Golang : Convert(cast) bigint to string
+9.4k Android Studio : Indicate progression with ProgressBar example
+18.6k Golang : Generate thumbnails from images
+21.4k Curl usage examples with Golang
+14.3k Golang : How to shuffle elements in array or slice?
+28.6k Golang : Read, Write(Create) and Delete Cookie example
+6.9k Mac OSX : Find large files by size
+8.5k Golang : How to check variable or object type during runtime?
+14.4k Golang : Recombine chunked files example
+4.5k Java : Generate multiplication table example
+23.9k Golang : Use regular expression to validate domain name