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
+10.1k Golang : Edge detection with Sobel method
+12.2k Golang : Detect user location with HTML5 geo-location
+30.4k Golang : How to redirect to new page with net/http?
+8.1k Golang : Check from web if Go application is running or not
+8.9k Golang : Sort lines of text example
+7.7k Golang : Mapping Iban to Dunging alphabets
+6.9k Fix sudo yum hang problem with no output or error messages
+22.2k Golang : Securing password with salt
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+5.6k Swift : Get substring with rangeOfString() function example
+26.7k Golang : How to check if a connection to database is still alive ?
+5.4k Golang : Reclaim memory occupied by make() example