Jump to content

Search the Community

Showing results for tags 'transforms'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. We often have to get a 2D from a 1D array. A good example is with StringRegExp : it can only return a 1D array. But it can be interesting to transform the result to a 2D array. Of course, it's easy to make it, but I think this function could help someone. First, an example : ; #EXAMPLE# ===================================================================================================================== #Include <Array.au3> Local $sString = "<select>" & @CRLF & _ " <option value='volvo'>Volvo</option>" & @CRLF & _ " <option value='saab'>Saab</option>" & @CRLF & _ " <option value='mercedes'>Mercedes</option>" & @CRLF & _ " <option value='audi'>Audi</option>" & @CRLF & _ " <option value='porsche'>Porsche</option>" & @CRLF & _ "</select>" Local $aValues = StringRegExp($sString, "value='([^']+)'>([^<]+)", 3) _ArrayDisplay($aValues, "1D Array") Local $aValues2D = _Array1DTo2D($aValues, 2, 0, 0, 0) _ArrayDisplay($aValues2D, "2D Array") ; =============================================================================================================================== Now, the function : ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Array1DTo2D ; Description ...: Transforms a 1D to a 2D array. ; Syntax ........: _Array1DTo2D($avArray, $iCols[, $iStart = 0[, $iEnd = 0[, $iFlag = 0]]]) ; Parameters ....: $avArray - Array to modify. ; $iCols - Number of columns to transform the array to. ; $iStart - [optional] Index of array to start the transformation. Default is the first element. ; $iEnd - [optional] Index of array to stop the transformation. Default is the last element. ; $iFlag - [optional] If set to 1, the array size must to a multiple of $iCols. Default is 0. ; Return values .: Success : Returns a 2D array ; Failure : Returns 0 and sets @error to : ; 1 - $aArray is not an array ; 2 - $iStart is greater than $iEnd ; 3 - $aArray is not a 1D array ; 4 - $aArray size is not a multiple of $iCols ; Author ........: jguinch ; =============================================================================================================================== Func _Array1DTo2D($avArray, $iCols, $iStart = 0, $iEnd = 0, $iFlag = 0) If $iStart = Default OR $iStart < 0 Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If NOT IsArray($avArray) Then Return SetError(1, 0, 0) If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, 0) Local $iUBound = UBound($avArray) - 1 If $iEnd < 1 Then $iEnd = $iUBound If $iEnd > $iUBound Then $iEnd = $iUBound If $iStart > $iEnd Then Return SetError(2, 0, 0) Local $iNbRows = ($iEnd - $iStart + 1) / $iCols If $iFlag AND IsFloat($iNbRows) Then Return SetError(2, 0, 0) Local $aRet[ Ceiling($iNbRows) ][$iCols] Local $iCol = 0, $iRow = 0 For $i = $iStart To $iEnd If $iCol = $iCols Then $iCol = 0 $iRow += 1 EndIf $aRet[$iRow][$iCol] = $avArray[$i] $iCol += 1 Next Return $aRet EndFunc I hope it is clear enough
×
×
  • Create New...