【问题标题】:Convert a string to an array in vlang在 vlang 中将字符串转换为数组
【发布时间】:2021-09-06 02:08:49
【问题描述】:

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

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

有什么方法可以将字符串转换为V中的数组?

【问题讨论】:

    标签: vlang


    【解决方案1】:

    您可以使用string.split(delim string) 来仅使用arraystring.bytes() 来获得arraybytes:

    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]
    

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 2017-11-27
      • 2021-05-09
      • 2023-03-19
      • 2022-11-29
      相关资源
      最近更新 更多