本帖最后由 C.L 于 2010-8-30 13:32 编辑
回复 7# cutyourchicken
_ArrayToString()函数只能转换1维数组吧?
好像你要转换的是2维数组,给你写个二维数组转换和还原的函数,直接转换成二进制数据,方便TCP传输:#include<array.au3>
Dim $a[2][3] = [[1,2,3],[3,4,5]]
$sArray = _Array2DToString ($a)
MsgBox (0,'二维数组二进制数据,$sArray)
$array = _StringToArray2D ($sArray)
_ArrayDisplay ($array,'还原二维数组')
Func _Array2DToString ($array)
Local $array1,$arrya2,$out = ""
$array1 = UBound($array,1)
$array2 = UBound($array,2)
$out = $array1&"|"&$array2
For $i=0 To $array1-1
For $j=0 To $array2-1
$out &= "|" & $array[$i][$j]
Next
Next
Return StringToBinary ($out,4)
EndFunc
Func _StringToArray2D($binData)
Local $temp
$string = BinaryToString ($binData,4)
$temp = StringSplit ($string,"|")
Local $array2d[$temp[1]][$temp[2]]
$k = 3
For $i=0 To $temp[1]-1
For $j=0 To $temp[2]-1
$array2d [$i][$j] = $temp [$k]
$k += 1
Next
Next
Return $array2d
EndFunc
|