Marnie Posted November 14, 2018 Share Posted November 14, 2018 Hello everyone, I desperately need help with parsing the string. "+" is delimiter, but "/" is telling you the number of variants Example of string (input): +AA1+BB1+CC1/CC2/CC3+DD4 Array should look like (output): Thanks Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted November 14, 2018 Share Posted November 14, 2018 @Marnie What did you try so far? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Marnie Posted November 14, 2018 Author Share Posted November 14, 2018 So far i have this and I am lost. It might be trivial ... how to proceed with For cycle and am I right at all ? expandcollapse popup#include <Array.au3> #include <String.au3> Global $word = "+AA1+BB1+CC1/CC2/CC3+DD4" Local $positionSlash = StringInStr($word,"/") if $positionSlash = 0 Then ConsoleWrite($word & @CRLF) ;pripadne arrayexplode podle + Else Local $firstPart = StringMid($word,1,$positionSlash-1) Local $positionPlus = StringInStr($word,"+",0,1,$positionSlash) if $positionPlus = 0 Then Null Else Local $followingPart1 = StringMid($word,$positionPlus,4) EndIf EndIf ConsoleWrite($firstPart & $followingPart1) ConsoleWrite($followingPart1) Local $FirstView = _StringExplode($word,"+") ;let's split to array according "+" sign _ArrayDisplay($FirstView) ;but how to proceed next - no idea ? Local $DivideSlash = _StringExplode($FirstView[4],"/") _ArrayDisplay($DivideSlash) ;StringRegExp($ZakladniBattle For $i=1 to UBound($FirstView) ConsoleWrite(StringRegExp($FirstView[$i],"/",2)) Next Link to comment Share on other sites More sharing options...
iamtheky Posted November 14, 2018 Share Posted November 14, 2018 based off your input how did you infer there was a CC4 entry? ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 14, 2018 Moderators Share Posted November 14, 2018 Marnie, And can you have multiple variants in the same line - such as: +AA1+BB1/BB2+CC1/CC2/CC3+DD4 ? And if so, what is the required output? 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...
Davidowicza Posted November 14, 2018 Share Posted November 14, 2018 Assuming that you cannot have multiple variants as @Melba23 has asked, (because that would just be a huge headache). This code should work, but may need some tweaking to fit into your script. Or if it does not work for what you want, it will point you in the right direction. ;but how to proceed next - no idea ? ; Trim any blank values in the array ; Move backwards through the array deleting the blank lines For $i = UBound($FirstView) - 1 To 0 Step -1 If $FirstView[$i] = "" Then _ArrayDelete($FirstView, $i) EndIf Next ;Find where you need to duplicate and split that duplication into another array for $x = 0 to UBound($FirstView)-1 Step 1 if Not StringInStr($FirstView[$x], "/") = 0 Then $location = $x $aData = _StringExplode($FirstView[$x], "/") ExitLoop EndIf Next ;Make a new array with bounds you have found $col = UBound($FirstView) $row = UBound($aData) local $FinalArray[$row][$col] ;double for loop to fill in the array For $x = 0 to UBound($FirstView)-1 Step 1 for $t = 0 to UBound($aData)-1 Step 1 if $x = $location Then $FinalArray[$t][$x] = $aData[$t] Else $FinalArray[$t][$x] = $FirstView[$x] EndIf Next Next _ArrayDisplay($FinalArray) Link to comment Share on other sites More sharing options...
Marnie Posted November 14, 2018 Author Share Posted November 14, 2018 38 minutes ago, iamtheky said: based off your input how did you infer there was a CC4 entry? sorry, that's a mistake Link to comment Share on other sites More sharing options...
Marnie Posted November 14, 2018 Author Share Posted November 14, 2018 33 minutes ago, Melba23 said: Marnie, And can you have multiple variants in the same line - such as: +AA1+BB1/BB2+CC1/CC2/CC3+DD4 ? And if so, what is the required output? M23 Yes, right. You can have multiple variants. In this case output would be look like this: Link to comment Share on other sites More sharing options...
Davidowicza Posted November 14, 2018 Share Posted November 14, 2018 If you use my code as a base, since it works with one variant, you should be able to add to it to look for multiple variants. It will be more complicated, but doable. Link to comment Share on other sites More sharing options...
mikell Posted November 14, 2018 Share Posted November 14, 2018 (edited) Funny challenge #Include <Array.au3> $str = "+AA1/AA2/AA3+BB1/BB2+CC1/CC2/CC3/CC4+DD4" $a = StringRegExp($str, '[^+]+', 3) Local $aRes[0][UBound($a)], $string, $sRes _LetsGo(0, "") _ArrayAdd($aRes, StringTrimRight($sRes, 2)) _ArrayDisplay($aRes) Func _LetsGo($k, $string) Local $tmp = StringSplit($a[$k], "/", 2) For $i = 0 to UBound($tmp) -1 If $k = UBound($a) -1 Then $sRes &= $string & $tmp[$i] & @crlf Else _LetsGo($k + 1, $string & $tmp[$i] & "|") EndIf Next EndFunc Edited November 14, 2018 by mikell typo... FrancescoDiMuro, boomingranny and Marnie 3 Link to comment Share on other sites More sharing options...
Marnie Posted November 14, 2018 Author Share Posted November 14, 2018 2 minutes ago, mikell said: Funny challenge #Include <Array.au3> $str = "+AA1/AA2/AA3+BB1/BB2+CC1/CC2/CC3/CC4+DD4" $a = StringRegExp($str, '[^+]+', 3) Local $aRes[0][UBound($a)], $string = "", $sRes _LetsGo(0, "") _ArrayAdd($aRes, StringTrimRight($sRes, 2)) _ArrayDisplay($aRes) Func _LetsGo($k, $string) Local $tmp = StringSplit($a[$k], "/", 2) For $i = 0 to UBound($tmp) -1 If $k = UBound($a) -1 Then $sRes &= $string & $tmp[$i] & @crlf Else _LetsGo($k + 1, $string & $tmp[$i] & "|") EndIf Next EndFunc Wow, thank you mate. Works like a charm 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