好玩的问题.AFAN兄17楼所说的确是个问题.
只是为了好玩,试下.
#include <Array.au3>
Local $Str = _
'Global Const $ALLOC_LOG_CONF = 0x00000002' & @CRLF & _
'Global Const $BASIC_LOG_CONF = 0x00000000' & @CRLF & _
'Global Const $BOOT_LOG_CONF = 0x00000003' & @CRLF & _
'Global Const $CM_ADD_ID_BITS = 0x00000001' & @CRLF & _
'Global Const $CM_ADD_ID_COMPATIBLE = 0x00000001 ;以下三个作用相同,只取一个' & @CRLF & _
'Global Const $CM_ADD_ID_COMPATIBLE = 0x1' & @CRLF & _
'Global Const $CM_ADD_ID_COMPATIBLE = 1' & @CRLF & _
'Global Const $CM_ADD_ID_HARDWARE = 0x00000000' & @CRLF & _
'Global Const $CM_BIND_CLASS_BIND_DEVINST = 0x6 ;类似,只取一个' & @CRLF & _
'Global Const $CM_BIND_PHYSNAME_BIND_DEVINST = 4, $CM_BIND_CLASS_BIND_DEVINST = 6' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_CLASS = 8' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_ID = 1' & @CRLF & _
'Dim Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_PHYSNAME = 2' & @CRLF & _
'Global Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32' & @CRLF & _
'Func _a($x)' & @CRLF & _
' Global Const $CM_BIND_CLASS_BIND_DEVINST = 8' & @CRLF & _
' If $x Then Global Const $CM_ADD_ID_COMPATIBLE = 1' & @CRLF & _
'EndFunc'
$Str=StringRegExp($str, '(?msi)^global.*?(?=\Qfunc\E)', 3)
$Str=$Str[0]
Local $Test = StringRegExp($str, '(?mi)^global.*?(\$[^=]+)=(.*?)(?=[\r\n;])', 3)
Local $Arr[UBound($Test)/2][2]
For $i=0 To UBound($Test)-1 Step 2
$Arr[$i/2][0]=$Test[$i]
$Arr[$i/2][1]=Number(StringStripWS($Test[$i+1],3))
Next
_ArrayDisplay($Arr)
$new_arr=ArrayUnique($Arr)
_ArrayDisplay($new_arr)
Func ArrayUnique($aArray, $iBase = 0, $oBase = 0, $iCase = 0)
If Not IsArray($aArray) Then Return SetError(1, 0, 0)
If UBound($aArray, 0) > 2 Then Return SetError(2, 0, 0)
Local $oD = ObjCreate('Scripting.Dictionary')
If @error Then Return SetError(4, 0, 0)
Local $dim2 = UBound($aArray, 2)
If $dim2 Then ;2D array
Local $dim1 = UBound($aArray, 1), $aUnique[$dim1][$dim2], $j
For $i = 0 to $dim1 - 1
If Not $oD.Exists($aArray[$i][0]) Then
$oD.Add($aArray[$i][0], 0)
$aUnique[$j][0] = $aArray[$i][0]
$aUnique[$j][1] = $aArray[$i][1]
$j += 1
Else
If Not $oD.item($aArray[$i][0])=$aArray[$i][1] Then $aUnique[$j-1][1]=$aArray[$i][1]
EndIf
Next
ReDim $aUnique[$j][2]
Else ;1D array
For $i In $aArray
If Not $oD.Exists($i) Then $oD.Add($i, 0)
Next
Local $aUnique = $oD.Keys()
EndIf
$oD.RemoveAll
$oD = ""
Return $aUnique
EndFunc
|