我正在学习V,就我的尝试而言,虽然V字符串是字节数组,但数组方法不适用于字符串。所以我想将字符串转换为数组。我尝试搜索这个但没有成功,我在 Go 中找到了一些东西,但它在 V 中不可用:
[]byte("Here is a string....")
Run Code Online (Sandbox Code Playgroud)
V中有什么办法可以将字符串转换为数组吗?
您可以使用string.split(delim string)to justarray和string.bytes()for an arrayof bytes:
Welcome to the V REPL (for help with V itself, type `exit`, then run `v help`).
V 0.2.2 8650ec6
Use Ctrl-C or `exit` to exit, or `help` to see other available commands
>>> x := "test"
>>> x.split("")
['t', 'e', 's', 't']
>>> x.bytes()
[t, e, s, t]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1053 次 |
| 最近记录: |