本帖最后由 huangke 于 2013-1-22 14:11 编辑
#include <Array.au3>
Local $avArray[10]
$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = " "
$avArray[3] = "Larry"
$avArray[4] = " "
$avArray[5] = "Valik"
$avArray[6] = " "
$avArray[7] = "Nutster"
$avArray[8] = " "
$avArray[9] = " "
_ArrayDisplay($avArray, "$avArray 原 _ArrayDelete()")
_ArrayDelete($avArray, 2)
_ArrayDelete($avArray, 4)
_ArrayDelete($avArray, 6)
_ArrayDelete($avArray, 8)
_ArrayDelete($avArray, 9)
_ArrayDisplay($avArray, "$avArray 后 _ArrayDelete()")
这样删除的话会出错的,因为数组个数变动了,空内容的ID会变,如:删除了$avArray[2]之后,$avArray[9]就会变成$avArray[8]了,待到_ArrayDelete($avArray, 8)的时候,$avArray[8]已经不是开始时候的$avArray[8]了。。。
有哪位大侠知道如何判断呢?
发帖两小时就解决,说明很简单嘛!给完整DD。
感谢 kevinch,afan,水木子(正则偷他的,嘻嘻!)
#include <Array.au3>
Local $avArray[10]
Dim $dic=ObjCreate("scripting.dictionary")
$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = " "
$avArray[3] = "Larry"
$avArray[4] = " "
$avArray[5] = "Valik"
$avArray[6] = " "
$avArray[7] = "Nutster"
$avArray[8] = " "
$avArray[9] = " "
_ArrayDisplay($avArray, "$avArray 原 _ArrayDelete()")
$i=1
For $n=0 To UBound($avArray)-1
$str = StringRegExpReplace($avArray[$n], "(?m)^\s+|(?m)\s+$", "")
If $str<>"" Then
$dic($i)=$avArray[$n]
$i+=1
EndIf
Next
$avArray=$dic.items
$dic=Null
_ArrayDisplay($avArray, "$avArray 后 _ArrayDelete()")
|