Search the Community
Showing results for tags '_arrayfromstring'.
-
Edit: This is now part of beta 3.3.15.4 __________________________________________________________________________________________________ There is a _ArrayToString() but no _ArrayFromString(). ( searched in the forum and google ) The example is based on the _ArrayToString() help file, to show the reconstruction of the array. #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[20] For $i = 0 To 19 $aArray[$i] = $i Next _ArrayDisplay($aArray, "1D Array") MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7)) ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString") Local $aArray[10][10] For $i = 0 To 9 For $j = 0 To 9 $aArray[$i][$j] = $i & "-" & $j Next Next _ArrayDisplay($aArray, "2D Array") MsgBox($MB_SYSTEMMODAL, "Rows 4-7, cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5)) ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString") ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFromString ; Description ...: Reconstruct an array from _ArrayToString() or _SQLite_Display2DResult()** ; Syntax ........: _ArrayFromString($sArrayStr[, $sDelim_Col = "|", [$sDelim_Row = @CRLF, [$bForce2D = False]]]) ; Parameters ....: $sArrayStr : A string formated by _ArrayToString() or _SQLite_Display2DResult()** ; $sDelim_Col : [optional] default is "|" ; $sDelim_Row : [optional] default is @CRLF ; $bForce2D : [optional] default is False. True will force a 2 dimensional array even if 1 dimensional. ; Return values .: Success - An array ; Failure - Return 0 with error = 1 ; Link...........: https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ ; Author ........: argumentum ; Remarks .......: ** for _SQLite_Display2DResult(), $sDelim_Col must be declared. ; =============================================================================================================================== Func _ArrayFromString($sArrayStr, $sDelim_Col = "|", $sDelim_Row = @CRLF, $bForce2D = False) If $sDelim_Col = Default Then $sDelim_Col = "|" If $sDelim_Row = Default Then $sDelim_Row = @CRLF If $bForce2D = Default Then $bForce2D = False Local $aRow, $aCol = StringSplit($sArrayStr, $sDelim_Row, 3) $aRow = StringSplit($aCol[0], $sDelim_Col, 3) If UBound($aCol) = 1 And Not $bForce2D Then For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) Next Return $aRow EndIf Local $aRet[UBound($aCol)][UBound($aRow)] For $n = 0 To UBound($aCol) - 1 $aRow = StringSplit($aCol[$n], $sDelim_Col, 3) If UBound($aRow) > UBound($aRet, 2) Then Return SetError(1) For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) $aRet[$n][$m] = $aRow[$m] Next Next Return $aRet EndFunc ;==>_ArrayFromString PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies ) #include <Array.au3>; For _ArrayDisplay() ; if you declare it, it will use it, else, use default ;Global $g_iniFile = @ScriptDir & "\ThisTest.ini" Example() Func Example() Local $n, $aTest, $aArray[3] = ["00", "one", "2"] ; if is not in the INI file, it will save it $aTest = IniGet("Test", $aArray) _ArrayDisplay($aTest, "1st") ; since is saved, it'll recall it $aTest = IniGet("Test") For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1) Next _ArrayDisplay($aTest, "2nd") EndFunc ;==>Example Func IniGet($sKey, $vDefault = Default, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1)) If $s = Chr(1) Then If $vDefault == Default Then Return SetError(1, 0, "") Else IniSet($sKey, $vDefault, $sSection) Return $vDefault EndIf EndIf $v = StringLeft($s, 1) Switch $v Case "i" Return Int(StringTrimLeft($s, 2)) Case "a" Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2)) Case "d" Return Binary(StringTrimLeft($s, 2)) Case Else Return String(StringTrimLeft($s, 2)) EndSwitch EndFunc ;==>IniGet Func IniSet($sKey, $vValue, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" If IsInt($vValue) Then $vValue = "i:" & $vValue ElseIf IsArray($vValue) Then $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2))) ElseIf IsBinary($vValue) Then $vValue = "d:" & $vValue Else $vValue = "s:" & $vValue EndIf $vValue = IniWrite($ini, $sSection, $sKey, $vValue) Return SetError(@error, @extended, $vValue) EndFunc ;==>IniSet ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFromString ; Description ...: Reconstruct an array from _ArrayToString() or _SQLite_Display2DResult()** ; Syntax ........: _ArrayFromString($sArrayStr[, $sDelim_Col = "|", [$sDelim_Row = @CRLF, [$bForce2D = False]]]) ; Parameters ....: $sArrayStr : A string formated by _ArrayToString() or _SQLite_Display2DResult()** ; $sDelim_Col : [optional] default is "|" ; $sDelim_Row : [optional] default is @CRLF ; $bForce2D : [optional] default is False. True will force a 2 dimensional array even if 1 dimensional. ; Return values .: Success - An array ; Failure - Return 0 with error = 1 ; Link...........: https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ ; Author ........: argumentum ; Remarks .......: ** for _SQLite_Display2DResult(), $sDelim_Col must be declared. ; =============================================================================================================================== Func _ArrayFromString($sArrayStr, $sDelim_Col = "|", $sDelim_Row = @CRLF, $bForce2D = False) If $sDelim_Col = Default Then $sDelim_Col = "|" If $sDelim_Row = Default Then $sDelim_Row = @CRLF If $bForce2D = Default Then $bForce2D = False Local $aRow, $aCol = StringSplit($sArrayStr, $sDelim_Row, 3) $aRow = StringSplit($aCol[0], $sDelim_Col, 3) If UBound($aCol) = 1 And Not $bForce2D Then For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) Next Return $aRow EndIf Local $aRet[UBound($aCol)][UBound($aRow)] For $n = 0 To UBound($aCol) - 1 $aRow = StringSplit($aCol[$n], $sDelim_Col, 3) If UBound($aRow) > UBound($aRet, 2) Then Return SetError(1) For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) $aRet[$n][$m] = $aRow[$m] Next Next Return $aRet EndFunc ;==>_ArrayFromString PS2: https://www.autoitscript.com/trac/autoit/ticket/3696#ticket <-- completed.
- 14 replies
-
- _arrayfromstring
- _arraytostring
- (and 3 more)