vlang - 将字符串转换为 vlang 中的数组

标签 vlang

我正在学习 V,就我的尝试而言,尽管 V 字符串是一个字节数组,但数组方法不适用于字符串。所以我想将字符串转换为数组。我试过搜索这个但没有成功,我在 Go 中找到了一些东西,但它在 V 中不可用:

[]byte("Here is a string....")

在V中有什么方法可以将字符串转换成数组吗?

最佳答案

您可以使用 string.split(delim string)只是 arraystring.bytes()对于 bytearray:

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/

相关文章:

c - 如何使用 Vlang 中的 C 库进行基本统计

vlang - V : iterate the characters (runes) of a string

vlang - 命令行解析 lib VLang

ubuntu - 如何修复 Ubuntu 中丢失的 Xcursor.h 文件?

vlang - 每行可以有多个结构成员吗?

vlang - 俱乐部某些模块中的变量 `C` 是什么?