我正在学习 V,就我的尝试而言,尽管 V 字符串是一个字节数组,但数组方法不适用于字符串。所以我想将字符串转换为数组。我试过搜索这个但没有成功,我在 Go 中找到了一些东西,但它在 V 中不可用:
[]byte("Here is a string....")
在V中有什么方法可以将字符串转换成数组吗?
最佳答案
您可以使用 string.split(delim string)
只是 array
和 string.bytes()
对于 byte
的 array
:
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]
关于vlang - 将字符串转换为 vlang 中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68084259/