1

我正在使用 For Each 迭代一个集合。每次我找到一个以“;”结尾的字符串时,我都需要删除那个“;”。(它用于 csv 解析,我有一个来自第三方的伪造文件)。

当我识别一行时,我希望它覆盖现有的值,例如“12;” 与“12”。

这段代码找到了所有正确的行,但没有覆盖 arrAccounts。

dim con
For Each con In arrAccounts(x)
    if Right(con,1) = ";" then
        dim length
        length =  Len(con)
        con = Left(con, (length-1))
    end if
next

我错过了什么/做错了什么?

4

1 回答 1

1

我认为唯一的事情是您必须再次将新值插入到数组中。

dim i, con
for i = 0 to ubound(arrAccounts(x)) ''# for keeping track which item we are looking at
    con = arrAccounts(x)(i)
    if right(con, 1) = ";" then
        con = left(con, len(con) - 1)
        arrAccounts(x)(i) = con ''# insert the new value back into the array at the same position
    end if
next
于 2012-04-18T13:29:04.397 回答