2012-04-18 53 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