偷工減料的方法
#include <Array.au3>
Local $read = _
'01 [["0xFFFFCC","0xCCFFFF","0xFFCCCC","0xFFCCCC","0xFFFF99","0xCCCCFF","0xFF9966","0xFF6666","0xFFCCCC"],["0xFFCC99","0xCCFF99","0xCCCCCC","0xFFCCCC","0xCCCCFF","0xCCFFCC","0xCCFFFF","0xCCCCCC","0xCCFF99"],["0xFFCCCC","0xFFFFFF","0x99CC99","0x99CCCC","0xFFCC99","0xFFCCCC","0xCCCCFF","0xFFCCCC","0xCCFFFF"],["0xFFCC99","0xFFFFCC","0x99CCCC","","","","","",""]]' & @CRLF & _
'02 [["0xCCFF99","0xFFFFFF","0x99CCFF","0x99CCCC","0xFFFFFF","0xCCFF99","0xCCFFCC","0xFFFFFF","0x66CCCC"],["0xCCCCFF","0xFFFFFF","0x99CCCC","0xCCFFCC","0x99CCCC","0xFFFFCC","0xCCFFFF","0xFFFFFF","0xCCCCFF"],["0xCCFFFF","0xFFFFFF","0x99CCFF","0x66CCFF","0xFFFFFF","0xCCFFFF","0x6699CC","0xFFFFFF","0x99CCFF"],["0xCCCCFF","0xFFFFFF","0x99CCFF","","","","","",""]]' & @CRLF & _
'03 [["0x66CCCC","0xCCFF66","0xFF99CC","0xFF9999","0xFFFFFF","0xFFCC99","0xFF6666","0xFFFF66","0x99CC66"],["0x666699","0xFFFFFF","0xFF9999","0x99CC33","0xFF9900","0xFFCC00","0xFF0033","0xFFFFFF","0xFF9966"],["0xFF9900","0xCCFF00","0xCC3399","0x99CC33","0xFFFFFF","0xFF6600","0x993366","0xCCCC33","0x666633"],["0x66CCCC","0xFFFFFF","0x666699","","","","","",""]]'
Local $arrColor = StringToExpression($read)
_ArrayDisplay($arrColor)
Exit
Func StringToExpression(ByRef $strArray, $varName = "Array")
Local $temp
$temp = StringRegExp($strArray, '([\[,])(?|"([^"]*+)"|(''([^'']*+)'')|())(?=[,\]])', 3)
If @error Then Return SetError(@error, @extended)
Local $arrResult[1][1]
Local $iRow = 0
Local $iCol = 0
Local $iMax = 1
For $i = 0 To UBound($temp) - 1 Step 2
Switch $temp[$i]
Case "["
$iRow += 1
$iCol = 1
ReDim $arrResult[$iRow][$iMax]
Case ","
$iMax = ($iCol > $iMax) ? $iCol : $iMax
ReDim $arrResult[$iRow][$iMax]
Case Else
ConsoleWrite("error: " & @error & @TAB & @extended & @TAB & $temp[$i + 1] & @CRLF)
EndSwitch
$arrResult[$iRow - 1][$iCol - 1] = $temp[$i + 1]
$iCol += 1
Next
Assign($varName, $arrResult, 1)
Return Eval($varName)
EndFunc ;==>StringToExpression
|