2012-04-18 62 views
1

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

当我确定一条线时,我希望它覆盖现有的值。 “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 

我在想什么/做错了什么?

+1

您可以使用'output = Replace(input,“;”,“”)'来移除分号。 – ZippyV 2012-04-18 13:38:08

回答

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 
+1

你现在就在我身上,而我刚才发现它。问题在于写入本地变量而不是传入参数。 – jvlarsen 2012-04-18 13:31:07

+0

好听!总是很高兴听到问题解决! – 2012-04-18 13:34:35