在bytes_test.go中,我看到: a := Split([]byte(tt.s), []byte(tt.sep), tt.n)其中tt.s和tt.sep是字符串。但是當(dāng)我嘗試去做 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
1 回答

慕少森
TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
以下是使用最新版本release.2010-03-04的有效代碼,其中包括以下更改:“存在一種語言更改:將字符串轉(zhuǎn)換為[] byte或[]的能力int。這不贊成使用string.Bytes和strings.Runes函數(shù)?!?/p>
package main
import ("bytes"; "fmt")
func main() {
a := bytes.Split([]byte("test"), []byte("e"), 0)
fmt.Println(a)
}
- 1 回答
- 0 關(guān)注
- 443 瀏覽
添加回答
舉報(bào)
0/150
提交
取消