strings.FieldsFunc() Function in Golang With Examples Last Updated : 19 Apr, 2020 Comments Improve Suggest changes Like Article Like Report strings.FieldsFunc() Function in Golang is used to splits the given string str at each run of Unicode code points c satisfying f(c) and returns an array of slices of str. Syntax: func FieldsFunc(str string, f func(rune) bool) []string Here, str is the given string, the rune is a built-in type meant to contain a single Unicode character and f is a user-defined function. Return: If all code points in str satisfy f(c) or the string is empty, an empty slice is returned. Note: This function makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash. Example 1: C // Golang program to illustrate the // strings.FieldsFunc() Function package main import ( "fmt" "strings" "unicode" ) func main() { // f is a function which returns true if the // c is number and false otherwise f := func(c rune) bool { return unicode.IsNumber(c) } // FieldsFunc() function splits the string passed // on the return values of the function f // String will therefore be split when a number // is encontered and returns all non-numbers fmt.Printf("Fields are: %q\n", strings.FieldsFunc("ABC123PQR456XYZ789", f)) } Output: Fields are: ["ABC" "PQR" "XYZ"] Example 2: C // Golang program to illustrate the // strings.FieldsFunc() Function package main import ( "fmt" "strings" "unicode" ) func main() { // f is a function which returns true if the // c is a white space or a full stop // and returns false otherwise f := func(c rune) bool { return unicode.IsSpace(c) || c == '.' } // We can also pass a string indirectly // The string will split when a space or a // full stop is encontered and returns all non-numbers s := "We are humans. We are social animals." fmt.Printf("Fields are: %q\n", strings.FieldsFunc(s, f)) } Output: Fields are: ["We" "are" "humans" "We" "are" "social" "animals"] Comment More infoAdvertise with us Next Article strings.FieldsFunc() Function in Golang With Examples V vanigupta20024 Follow Improve Article Tags : Go Language Golang-String Similar Reads strings.Fields() Function in Golang With Examples strings.Fields() Function in Golang is used to splits the given string around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of str or an empty slice if str contains only white space. Syntax: func Fields(str string) []s 2 min read strings.Map() Function in Golang With Examples strings.Map() Function in Golang is used to return a copy of the string given string with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement. So whenever the user wants to make changes in a 2 min read strings.Join() Function in Golang With Examples strings.Join() Function in Golang concatenates all the elements present in the slice of string into a single string. This function is available in the string package. Syntax: func Join(s []string, sep string) string Here, s is the string from which we can concatenate elements and sep is the separato 1 min read fmt.Sprint() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprint() function in Go language formats using the default formats for its operands and returns the resulting string. Here spaces are added between operands when any string is 3 min read fmt.Sprintf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintf() function in Go language formats according to a format specifier and returns the resulting string. Moreover, this function is defined under the fmt package. Here, you 2 min read Like