在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
1 回答

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