# Function Reference

# _ArrayFromString

Reconstruct an array from _ArrayToString() or _SQLite_Display2DResult()

#include <Array.au3>
_ArrayFromString ( $sArrayStr [, $sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $bForce2D = False [, $iStripWS = $STR_STRIPLEADING + $STR_STRIPTRAILING]]]] )

## 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.
$iStripWS | [optional] default is 3. This is the flag for StringStripWS(). Set to zero to disable.

## Return Value

Success: | An array
Failure: | Set @error Flag to non zero.

## Remarks

** for _SQLite_Display2DResult(), $sDelim_Col must be declared.
Note that _ArrayToString() will return an empty string when passed any of the following array formats with no content - [0], [1], [0][0], [1][0], [0][1], [1][1]. This function cannot therefore distinguish between these cases and returns as default a single element array with no content: either [1] or [1][1] depending on the $bForce2D flag.

## Related

_ArrayToString, _SQLite_Display2DResult

## Example

### Example 1

    #include <Array.au3>
    #include <Debug.au3>
    #include <MsgBoxConstants.au3>

    Example()

    Func Example()
        Local $aArrayFromText = _ArrayFromString("  1|2  ") ;               by default, LEADING and TRAILING
        _DebugArrayDisplay($aArrayFromText, UBound($aArrayFromText, $UBOUND_DIMENSIONS) & "D") ; spaces are removed.

        $aArrayFromText = _ArrayFromString("1|2", Default, Default, True) ; force 2D array
        _DebugArrayDisplay($aArrayFromText, UBound($aArrayFromText, $UBOUND_DIMENSIONS) & "D")

        $aArrayFromText = _ArrayFromString("1|2" & @CRLF & "3|4")
        _DebugArrayDisplay($aArrayFromText, UBound($aArrayFromText, $UBOUND_DIMENSIONS) & "D")

    EndFunc   ;==>Example

### Example 2

    #include <Array.au3>
    #include <Debug.au3>
    #include <MsgBoxConstants.au3>
    #include <SQLite.au3>
    #include <SQLite.dll.au3>

    Example()

    Func Example()
        Local $aResult, $iRows, $iColumns, $iRval, $sText, $aArrayFromText

        _SQLite_Startup()
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!")
            Exit -1
        EndIf
        ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)

        _SQLite_Open() ; Open a :memory: database
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!")
            Exit -1
        EndIf

        ; Example Table
        ; Name        | Age
        ; -----------------------
        ; Alice       | 43
        ; Bob         | 28
        ; Cindy       | 21

        If Not _SQLite_Exec(-1, "CREATE TEMP TABLE persons (Name, Age);" & _
                "INSERT INTO persons VALUES ('Alice','43');" & _
                "INSERT INTO persons VALUES ('Bob','28');" & _
                "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
                MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

        ; Query
        $iRval = _SQLite_GetTable2D(-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
        If $iRval = $SQLITE_OK Then

            ConsoleWrite('--- --- --- ---' & @CRLF)
            _SQLite_Display2DResult($aResult)
            ConsoleWrite('--- --- --- ---' & @CRLF)

            ; demo using _SQLite_Display2DResult()
            $sText = _SQLite_Display2DResult($aResult, Default, True, @TAB)
            ConsoleWrite($sText & @CRLF) ; ..say, you save this in a log file ...
            $aArrayFromText = _ArrayFromString($sText, @TAB) ; ... then rebuild the array
            _DebugArrayDisplay($aArrayFromText, "from _SQLite_Display2DResult()")
            ConsoleWrite('--- --- --- ---' & @CRLF)

            ; demo using _ArrayToString()
            $sText = _ArrayToString($aResult)
            ConsoleWrite($sText & @CRLF)
            $aArrayFromText = _ArrayFromString($sText)
            _DebugArrayDisplay($aArrayFromText, "from _ArrayToString()")
            ConsoleWrite('--- --- --- ---' & @CRLF)

        Else
            MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
        EndIf

        _SQLite_Close()
        _SQLite_Shutdown()
    EndFunc   ;==>Example