Golang bytes.Fields() function example
package bytes
Fields splits the input slice around each instance of one or more consecutive white space characters.
Golang bytes.Fields() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
strslice := []byte("a b c d e f \tg") // \t is tab space
for i, subslice := range bytes.Fields(strslice) {
fmt.Printf("Counter %d : %s \n", i, string(subslice))
}
}
Output :
Counter 0 : a
Counter 1 : b
Counter 2 : c
Counter 3 : d
Counter 4 : e
Counter 5 : f
Counter 6 : g
Advertisement
Something interesting
Tutorials
+5.7k List of Golang XML tutorials
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+22.7k Golang : Strings to lowercase and uppercase example
+18.2k Golang : Get path name to current directory or folder
+21.6k Golang : Encrypt and decrypt data with TripleDES
+6.2k Golang : Extract XML attribute data with attr field tag example
+14.1k Javascript : Prompt confirmation before exit
+11.6k Golang : Fuzzy string search or approximate string matching example
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+13.6k Golang : Set image canvas or background to transparent
+8.6k Golang : Set or add headers for many or different handlers