FrancescoDiMuro Posted April 14, 2017 Posted April 14, 2017 Good evening I was looking around the forum if I could find a function that allows to convert a string into a 2 dimensional array... The first column of the array is always the same, but the rows could change... I have a pattern like: Column A|Column B Static Text 1|Data 1 Static Text 2|Data 2 Static Text 3|Data 3 Static Text 4|Data 4 Where, Static Text (1...4) will be always the same, and I don't want to change them... But, Data 1...4 are dynamic fields... So, I could have the pattern above AND I coould have the pattern I'm going to show you right below Column A|Column B Static Text 1|Data 1 Static Text 2|Data 2 Static Text 3|Data 3 Static Text 4|Data 4 Static Text 1|Data 5 Static Text 2|Data 6 Static Text 3|Data 7 Static Text 4|Data 8 How can I do in this case? Thanks for everyone's help Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
spudw2k Posted April 14, 2017 Posted April 14, 2017 That should be easy enough to accomplish. One question I have is: where, and in what format, does the data come in (text file, string at a time, etc.)? The clearer the requirements, the less re-work will be needed to shape the code to fit the data input. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
FrancescoDiMuro Posted April 14, 2017 Author Posted April 14, 2017 Hi @spudw2k Thanks for asking. The string comes from a For...In Loop, and it's in the string format... So I do something like this: For $oElement In $oQuery $sStringToArray &= $oElement.SomeData1 & _ $oElement.SomeData2 & _ $oElement.SomeDataN Next And the, I use StringSplit() to obtain the array... Thanks for your help! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
spudw2k Posted April 14, 2017 Posted April 14, 2017 (edited) Ok, so is the following produced after StringSplit?Column A|Column BStatic Text 1|Data 1Static Text 2|Data 2Static Text 3|Data 3Static Text 4|Data 4So this ^ is already a single dimension array? I am curious, what does the string look like before you perform the StringSplit, particularly what delimiter are you using? Just trying to get a clear picture. Edited April 14, 2017 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
spudw2k Posted April 14, 2017 Posted April 14, 2017 Here is one fairly simple solution. #include <MsgBoxConstants.au3> ;$STR_NOCOUNT Const #include <Array.au3> ;_Array* Functions Local $aArray[]=["Column A|Column B","Static Text 1|Data 1","Static Text 2|Data 2","Static Text 3|Data 3","Static Text 4|Data 4"] ;Demo array to mimic dataset _ArrayDisplay($aArray, "Starting Dataset") ;Dataset look correct? Local $a2DArr = StringSplit($aArray[0],"|",$STR_NOCOUNT) ;Create new Array with first row of dataset above (Header) _ArrayTranspose($a2DArr) ;Convert to 2D array For $iX = 1 To UBound($aArray)-1 ;Fill 2D Array _ArrayAdd($a2DArr,$aArray[$iX]) Next _ArrayDisplay($a2DArr, "Populated 2D array") ;Display filled 2D array Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Moderators JLogan3o13 Posted April 14, 2017 Moderators Posted April 14, 2017 Just out of curiosity, why not move the logic up a level and use _ArrayAdd, like so: ;instead of For $oElement In $oQuery $sStringToArray &= $oElement.SomeData1 & _ $oElement.SomeData2 & _ $oElement.SomeDataN Next ... StringSplit... etc... ;Define your array ahead of time, then populate it through your For Loop For $oElement In $oQuery _ArrayAdd($myArray, $oElement.SomeData1 & "|" & $oElement.SomeData2 & "|" & $oElement.SomeDataN Next FrancescoDiMuro 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
spudw2k Posted April 14, 2017 Posted April 14, 2017 @JLogan3o13 Agreed, the sooner (less work) the dataset can be formatted the better. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Luigi Posted April 14, 2017 Posted April 14, 2017 #include-once #include <Array.au3> Local $string = "Column A|Column B" & @CRLF & _ "Static Text 1|Data 1" & @CRLF & _ "Static Text 2|Data 2" & @CRLF & _ "Static Text 3|Data 3" & @CRLF & _ "Static Text 4|Data 4" Local $arr[1][2] _ArrayAdd($arr, $string, 0, "|", @CRLF) _ArrayDelete($arr, 0) _ArrayDisplay($arr) spudw2k 1 Visit my repository
iamtheky Posted April 14, 2017 Posted April 14, 2017 can you show a couple of legit values? What are you splitting on? There is no pipe or CR added during the loop you provided just somedataX smashed together for ubound number of times. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
spudw2k Posted April 14, 2017 Posted April 14, 2017 @Luigi My first shot was like yours, but I opted to avoid using _ArrayDelete for the first (empty) row. Doing some quick perf comparrisons, it doesn't seem to have major impact. Good stuff. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
iamtheky Posted April 14, 2017 Posted April 14, 2017 (edited) #include <array.au3> local $aArray[0][2] local $oQuery = ["Static Text 1" , "Data 1" , "Static Text 2" , "Data 2" , "Static Text 3" , "Data 3" ,"Static Text 4" , "Data 4"] $flag = "" $i = 0 For $oElement In $oQuery If $flag = 0 Then _ArrayAdd($aArray , $oQuery[$i] , 0) $flag = 1 $i+=1 Else $aArray[ubound($aArray) - 1][1]=$oQuery[$i] $flag = 0 $i+=1 EndIf Next _ArrayDisplay($aArray) I ask because it seems you could do it in the loop, if the return is any kind of reliable format. I don't have a nice object example but the above array example should accurately reflect the thought Edited April 14, 2017 by iamtheky spudw2k 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
spudw2k Posted April 14, 2017 Posted April 14, 2017 @iamtheky I didn't know you could declare an array like that ($aArray[0][2]), pretty cool.@Luigi That ^ would eliminate the need for the _ArrayDelete Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Luigi Posted April 14, 2017 Posted April 14, 2017 (edited) #include <array.au3> Local $aArray[0][2] Local $oQuery = ["Static Text 1", "Data 1", "Static Text 2", "Data 2", "Static Text 3", "Data 3", "Static Text 4", "Data 4", "IMPAR(ODD)"] Local $iSize = UBound($oQuery, 1) - 1 If Not Mod($iSize, 2) Then _ArrayAdd($oQuery, "") $iSize += 1 EndIf For $ii = 0 To $iSize Step 2 _ArrayAdd($aArray, $oQuery[$ii] & "|" & $oQuery[$ii + 1], "|") Next _ArrayDisplay($aArray) Edited April 14, 2017 by Luigi Visit my repository
iamtheky Posted April 14, 2017 Posted April 14, 2017 you need the additional conditions if using a For..In Loop, or you will blow the bounds ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Luigi Posted April 14, 2017 Posted April 14, 2017 (edited) 35 minutes ago, iamtheky said: local $aArray[0][2] I did not know this was possible ! WOW! I learned one more today. Edited April 14, 2017 by Luigi Visit my repository
Luigi Posted April 14, 2017 Posted April 14, 2017 4 minutes ago, iamtheky said: you need the additional conditions if using a For..In Loop, or you will blow the bounds I thinking about this... if the size is multiple of 2, I believe have no problem... But, if not... There is a problem. Visit my repository
FrancescoDiMuro Posted April 19, 2017 Author Posted April 19, 2017 Good evening guys Thanks everyone for the replies... Sorry for my late and not deyailed answer, but,natm, I'm sick ( a bad cold with some fever ), and with no Internet connection, so, thanks and sorry! As soon as I get better, I'll try to reply to you guys Again, a big thank you, and have a good day Francesco Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
FrancescoDiMuro Posted May 8, 2017 Author Posted May 8, 2017 On 14/4/2017 at 6:55 PM, JLogan3o13 said: Just out of curiosity, why not move the logic up a level and use _ArrayAdd, like so: ;instead of For $oElement In $oQuery $sStringToArray &= $oElement.SomeData1 & _ $oElement.SomeData2 & _ $oElement.SomeDataN Next ... StringSplit... etc... ;Define your array ahead of time, then populate it through your For Loop For $oElement In $oQuery _ArrayAdd($myArray, $oElement.SomeData1 & "|" & $oElement.SomeData2 & "|" & $oElement.SomeDataN Next Good evening @JLogan3o13! In this case, how can I have a 2D array? Should I do something like this? For $oElement In $oQuery _ArrayAdd($myArray, $sHeaderRow1 & "|" & $oElement.SomeData1 & @CRLF & _ $sHeaderRow2 & "|" & $oElement.SomeData2 & @CRLF & _ $sHeaderRowN & "|" & $oElement.SomeDataN Next Thank you Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Moderators JLogan3o13 Posted May 8, 2017 Moderators Posted May 8, 2017 6 minutes ago, FrancescoDiMuro said: Should I do something like this? Why are you putting a carriage return in your elements? Have you tried it yourself, to determine if it comes out as you would expect? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
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