GO語言"bytes"包中"FieldsFunc"函數的用法及代碼示例。
用法:
func FieldsFunc(s []byte, f func(rune) bool) [][]byte
FieldsFunc 將 s 解釋為 UTF-8 編碼的代碼點序列。它在每次運行滿足 f(c) 的代碼點 c 處拆分切片 s,並返回 s 的子切片切片。如果 s 中的所有代碼點都滿足 f(c) 或 len(s) == 0,則返回一個空切片。
FieldsFunc 不保證它調用 f(c) 的順序,並假設 f 對於給定的 c 總是返回相同的值。
例子:
package main
import (
"bytes"
"fmt"
"unicode"
)
func main() {
f := func(c rune) bool {
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
}
fmt.Printf("Fields are: %q", bytes.FieldsFunc([]byte(" foo1;bar2,baz3..."), f))
}
輸出:
Fields are: ["foo1" "bar2" "baz3"]
相關用法
- GO Fields用法及代碼示例
- GO FileServer用法及代碼示例
- GO FileMode用法及代碼示例
- GO FixedZone用法及代碼示例
- GO Fscanln用法及代碼示例
- GO Float.SetString用法及代碼示例
- GO Fprintln用法及代碼示例
- GO FormatMediaType用法及代碼示例
- GO Float64s用法及代碼示例
- GO Fprintf用法及代碼示例
- GO Fprint用法及代碼示例
- GO Floor用法及代碼示例
- GO FormatUint用法及代碼示例
- GO FormatBool用法及代碼示例
- GO Float64sAreSorted用法及代碼示例
- GO Float.Scan用法及代碼示例
- GO FormatFloat用法及代碼示例
- GO FullRune用法及代碼示例
- GO FullRuneInString用法及代碼示例
- GO Float.Add用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 FieldsFunc。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。