如何从字符串中仅收集数字并构建它们的列表?


0

我有一列单元格如:[[[3,0,[5.0,6.0]],[6.0,6,0],[3.0,[6.0,5.0]]] 如何断开其字符串以使该单元格中的每个数值都附加到带有VBA的列表/数组中?


遍历专栏。更换 []""。然后拆分 ,。迭代拆分字符串,将每个部分添加到数组中。
Scott Craner

我得到了,但是有可能将它们放在一个列表中,可以告诉它们如何被括号括起来,即我的案例的输出是:array =(“3.0”,“5.0,6.0”,“ 6.0,6.0“,”3.0“,”6.0,5.0“)我明白如果这太多了,我整天都在尝试各种循环
Ognox

Answers:


0

看看下面的例子:

Sub Test()

    q = "[[[3.0, [5.0, 6.0]], [6.0, 6.0], [3.0, [6.0, 5.0]]]"
    Do
        w = Len(q)
        q = Replace(q, "[[", "[")
        q = Replace(q, "]]", "]")
    Loop Until w = Len(q)
    q = Replace(q, "], [", "|")
    q = Replace(q, ", [", "|")
    q = Replace(q, "],", "|")
    q = Mid(q, 2, Len(q) - 2)
    a = Split(q, "|")

End Sub

结果数组:

locals

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.