johnmcloud Posted January 28, 2015 Share Posted January 28, 2015 (edited) Hello guys, I need a little help for make a multidimensional array in this way: I have a string delimited with "|" and i need to split between column, i have already make it: abc abc abc Now from every colum i need to split each character in this way a a a b b b c c c But if the character is between [ ] leave it in a single row, like: a a a b b [a12] c c c [a33] d f Is clear enought? If not i'll try to explain better. My initial script: #include <Array.au3> ; Only for _ArrayDisplay() $sString = "testabc[12a]|test2589|test3578[34asd]|test4877" StringReplace($sString, "|", "|") $iCol = @extended Global $aArray[1][$iCol+1] $aCols = StringSplit($sString, "|", 1) For $c = 1 To $aCols[0] $aArray[0][$c - 1] = $aCols[$c] Next _ArrayDisplay($aArray, "$aArray") ; until here is ok For $x = 0 To UBound($aArray, 2) - 1 ;StringSplit($aArray[0][$x], "", 1) ; split each char Next Thanks Edited January 28, 2015 by johnmcloud Link to comment Share on other sites More sharing options...
kylomas Posted January 28, 2015 Share Posted January 28, 2015 (edited) Johnmcloud, Like this??? #include <Array.au3> ; Only for _ArrayDisplay() $sString = "testabc[12a]|test2589|test3578[34asd]|test4877|abc[123]xyz" StringReplace($sString, "|", "|") $iCol = @extended Global $aArray[1][$iCol+1] $aCols = StringSplit($sString, "|", 1) For $c = 1 To $aCols[0] $aArray[0][$c - 1] = $aCols[$c] Next ;_ArrayDisplay($aArray, "$aArray") ; until here is ok local $space = true, $sTmp For $x = 0 To UBound($aArray, 2) - 1 for $1 = 1 to stringlen($aArray[0][$x]) if stringmid($aArray[0][$x],$1,1) = '[' then $space = not $space if not $space and stringmid($aArray[0][$x],$1,1) = ']' then $space = not $space $sTmp &= ($space) ? stringmid($aArray[0][$x],$1,1) & ' ' : stringmid($aArray[0][$x],$1,1) Next $aArray[0][$x] = $sTmp $sTmp = '' Next _ArrayDisplay($aArray) It's 4:00AM and I could NOT work out the regexp for this so you get it the long winded way... edit: corrected the for loop (should have started at 1 Edited January 28, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
johnmcloud Posted January 28, 2015 Author Share Posted January 28, 2015 No Like this: expandcollapse popup#include <Array.au3> ; Only for _ArrayDisplay() $sString = "testabc[12a]|test2589|test3578[34asd]|abc[123]xyzuea" Local $aArray[10][4] $aArray[0][0] = "t" $aArray[1][0] = "e" $aArray[2][0] = "s" $aArray[3][0] = "t" $aArray[4][0] = "a" $aArray[5][0] = "b" $aArray[6][0] = "c" $aArray[7][0] = "[12a]" $aArray[0][1] = "t" $aArray[1][1] = "e" $aArray[2][1] = "s" $aArray[3][1] = "t" $aArray[4][1] = "2" $aArray[5][1] = "5" $aArray[6][1] = "8" $aArray[7][1] = "9" $aArray[0][2] = "t" $aArray[1][2] = "e" $aArray[2][2] = "s" $aArray[3][2] = "t" $aArray[4][2] = "3" $aArray[5][2] = "5" $aArray[6][2] = "7" $aArray[7][2] = "8" $aArray[7][2] = "[34asd]" $aArray[0][3] = "a" $aArray[1][3] = "b" $aArray[2][3] = "c" $aArray[3][3] = "[123]" $aArray[4][3] = "x" $aArray[5][3] = "y" $aArray[6][3] = "z" $aArray[7][3] = "u" $aArray[8][3] = "e" $aArray[9][3] = "a" _ArrayDisplay($aArray) Thanks anyway Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted January 28, 2015 Moderators Solution Share Posted January 28, 2015 johnmcloud,This seems to work: expandcollapse popup#include <Array.au3> ; Only for _ArrayDisplay() $sString = "testabc[12a]|test2589|test3578[34asd]|abc[123]xyzuea" Local $aArray[10][4] $aArray[0][0] = "t" $aArray[1][0] = "e" $aArray[2][0] = "s" $aArray[3][0] = "t" $aArray[4][0] = "a" $aArray[5][0] = "b" $aArray[6][0] = "c" $aArray[7][0] = "[12a]" $aArray[0][1] = "t" $aArray[1][1] = "e" $aArray[2][1] = "s" $aArray[3][1] = "t" $aArray[4][1] = "2" $aArray[5][1] = "5" $aArray[6][1] = "8" $aArray[7][1] = "9" $aArray[0][2] = "t" $aArray[1][2] = "e" $aArray[2][2] = "s" $aArray[3][2] = "t" $aArray[4][2] = "3" $aArray[5][2] = "5" $aArray[6][2] = "7" $aArray[7][2] = "8" $aArray[7][2] = "[34asd]" $aArray[0][3] = "a" $aArray[1][3] = "b" $aArray[2][3] = "c" $aArray[3][3] = "[123]" $aArray[4][3] = "x" $aArray[5][3] = "y" $aArray[6][3] = "z" $aArray[7][3] = "u" $aArray[8][3] = "e" $aArray[9][3] = "a" _ArrayDisplay($aArray, "Original", Default, 8) ; ############################### ; Split string on delimiter $aSplit_1 = StringSplit($sString, "|") ; Create array with correct number of columns Global $aFinalArray[1][$aSplit_1[0]] ; Loop through the split array For $i = 1 To $aSplit_1[0] ; Extract line $sLine = $aSplit_1[$i] ; Get line length $iLen = StringLen($sLine) ; Create hold all chars if necessary Global $aSplit_2[$iLen + 1] ; Set indices $iWriteindex = 0 For $iReadIndex = 1 To $iLen ; Get char $sChar = StringMid($sLine, $iReadIndex, 1) ; Add to array $aSplit_2[$iWriteindex] = $sChar ; if starting a [...] section If $sChar = "[" Then Do ; Keep looping through the line $iReadIndex += 1 $sChar = StringMid($sLine, $iReadIndex, 1) ; Add all chars to the same element until end of [...] section $aSplit_2[$iWriteindex] &= $sChar Until $sChar = "]" EndIf ; Move to next element $iWriteindex += 1 Next ; Just to see what happened ;_ArrayDisplay($aSplit_2, $sLine, Default, 8) ; ReDim final array if required If UBound($aFinalArray) < $iWriteindex Then ReDim $aFinalArray[$iWriteindex][$aSplit_1[0]] EndIf ; Add elements to final array For $j = 0 To $iWriteindex - 1 $aFinalArray[$j][$i - 1] = $aSplit_2[$j] Next Next ; And here is the result _ArrayDisplay($aFinalArray, "M23", Default, 8)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted January 28, 2015 Author Share Posted January 28, 2015 (edited) Yes, seems work fine Thanks Melba, i'll check it out EDIT: Checked and integrated with the main script, work without problems. Thanks again Edited January 28, 2015 by johnmcloud Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now