ida*_*dov 2 string byte types go
在bytes_test.go中我看到:
a := Split([]byte(tt.s), []byte(tt.sep), tt.n)
Run Code Online (Sandbox Code Playgroud)
其中 tt.s 和 tt.sep 是字符串。但是当我尝试做的时候
a := bytes.Split([]byte("test"), []byte("e"), 0)
Run Code Online (Sandbox Code Playgroud)
我得到:
cannot convert "test" (type ideal string) to type []uint8 in conversion
cannot convert "e" (type ideal string) to type []uint8 in conversion
Run Code Online (Sandbox Code Playgroud)
以下是使用最新版本(release.2010-03-04)的有效代码,其中包括以下更改:“有一项语言更改:能够将字符串转换为 []byte 或 [] int。这会弃用 strings.Bytes 和 strings.Runes 函数。”
package main
import ("bytes"; "fmt")
func main() {
a := bytes.Split([]byte("test"), []byte("e"), 0)
fmt.Println(a)
}
Run Code Online (Sandbox Code Playgroud)
更新到当前版本的 Go:安装 Go:跟上版本。
| 归档时间: |
|
| 查看次数: |
6785 次 |
| 最近记录: |