VB - 附加到数组? [英] VB - Append to array?

查看:103
本文介绍了VB - 附加到数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题。但我有这阵,我需要从剥离无用的部分。但我还是希望它在数组中。

this is probably a super simple question. But I have this Array that I need to strip useless parts from. But I still want it in an array.

因此​​,阵列看起来是这样的,当谈到在:

So, the array looks like this when it comes in:

ArrValues(0) "Firstname=FIRSTNAME"
ArrValues(1) "Lastname=LASTNAME"
ArrValues(2) "Username=USERNAME"
ArrValues(3) "Displayname=DISPLAYNAME"

然后,我通过这个code片段发送此数组:

Then I send this array through this code snippet:

For Each s In arrValues
    s = Split(s, "=")
    s = s(1)
Next

这条弦,所以我只得到 FIRSTNAME 等。
但是,我想每个清洁串再次发送到一个数组。我该怎么做呢?

This strips the strings so I get only FIRSTNAME and so on. But, I want to send each cleaned string into an array again. How do I do that?

推荐答案

只要你有一个=号的所有字符串,这个code应该工作...使用MID函数。我不是性能专家,但我相信MID函数将具有比SPLIT更好的性能(因为拆分将REDIM每个值)。

As long as you have all strings with an '=' sign, this code should work... using MID function. I'm not an performance expert, but I believe that a MID function would have a better performance than the SPLIT (since split will redim each value).

不过,海伦的code可以正常工作。就在这个共享code,以显示我的MID做法:)

Still, Helen's code might work as well. Just sharing this code to show my MID approach :)

Sub MidArray()

    Dim ArrValues(3) As Variant
    Dim vValue As Variant
    Dim iCount As Integer

    ArrValues(0) = "Firstname=FIRSTNAME"
    ArrValues(1) = "Lastname=LASTNAME"
    ArrValues(2) = "Username=USERNAME"
    ArrValues(3) = "Displayname=DISPLAYNAME"

    For iCount = LBound(ArrValues) To UBound(ArrValues)

        ArrValues(iCount) = Mid(ArrValues(iCount), InStr(ArrValues(iCount), "=") + 1)

    Next iCount

End Sub

这篇关于VB - 附加到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆