bytes.Split分隔符为[] byte(“…”)

在bytes_test.go中,我看到:

 a := Split([]byte(tt.s), []byte(tt.sep), tt.n)

其中tt.s和tt.sep是字符串。但是当我尝试去做

 a := bytes.Split([]byte("test"), []byte("e"), 0)

我得到:

 cannot convert "test" (type ideal string) to type []uint8 in conversion
 cannot convert "e" (type ideal string) to type []uint8 in conversion


一只名叫tom的猫
浏览 398回答 1
1回答

慕少森

以下是使用最新版本release.2010-03-04的有效代码,其中包括以下更改:“存在一种语言更改:将字符串转换为[] byte或[]的能力int。这不赞成使用string.Bytes和strings.Runes函数。”package mainimport ("bytes"; "fmt")func main() {    a := bytes.Split([]byte("test"), []byte("e"), 0)    fmt.Println(a)}
打开App,查看更多内容
随时随地看视频慕课网APP