Felicitas Posted October 13, 2021 Share Posted October 13, 2021 Hello again, i´m a little bit in trouble trying to extract the five-digit number from a string i have an array like this: array arraynew row1 112 56985 1 589 6 56985 row2 15896 25 25 3636 15896 row3 6 6 8956 56895 4 56895 .... Does someone have an good idea? Thank you for your help. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 13, 2021 Moderators Solution Share Posted October 13, 2021 Felicitas: Try this: #include <Array.au3> Global $aArray[] = ["112 56985 1 589 6", "15896 25 25 3636", "6 6 8956 56895 4"] Global $aNewArray[UBound($aArray)] For $i = 0 To UBound($aArray) - 1 ; Get array of all 5 digit numbers in element $aRet = StringRegExp($aArray[$i], "\d{5}", 3) ; Add returned string to the new array $aNewArray[$i] = $aRet[0] Next _ArrayDisplay($aNewArray, "", Default, 8) I leave error-checking to you - and no doubt a real guru will be along soon to do the whole thing in one line! 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...
mikell Posted October 13, 2021 Share Posted October 13, 2021 5 hours ago, Melba23 said: do the whole thing in one line No way to do a one-liner using StringRegExp directly on an array The only one I can think of is this #include <Array.au3> Global $aArray[] = ["112 56985 1 589 6", "15896 25 25 3636", "6 6 8956 56895 4"] Global $aNewArray = StringRegExp(_ArrayToString($aArray), "\d{5}", 3) _ArrayDisplay($aNewArray, "", Default, 8) Link to comment Share on other sites More sharing options...
Felicitas Posted October 14, 2021 Author Share Posted October 14, 2021 thank you so much, it works perfectly... is there an option to get an array with the empty rows? for example: row1 112 56985 1 589 6 56985 row2 15 4 123 23 623 8 "Null" row3 6 6 8956 56895 41 56895 row4 "Null" row5 15557 15 1 1 1556 15557 thank you for your help :) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2021 Moderators Share Posted October 14, 2021 Felicitas, Quote is there an option to get an array with the empty rows? Of course: #include <Array.au3> Global $aArray[] = ["12 56985 1 589 6", "15 4 123 23 623 8", "6 6 8956 56895 41", "", "15557 15 1 1 1556"] Global $aNewArray[UBound($aArray)] For $i = 0 To UBound($aArray) - 1 ; Get array of all 5 digit numbers in element $aRet = StringRegExp($aArray[$i], "\d{5}", 3) If Not @error Then ; Add returned string to the new array $aNewArray[$i] = $aRet[0] Else ; Or place "Null" $aNewArray[$i] = "Null" EndIf Next _ArrayDisplay($aNewArray, "", 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...
mikell Posted October 14, 2021 Share Posted October 14, 2021 For the fun challenge #include <Array.au3> Global $aArray[] = ["12 56985 1 589 6", "15 4 123 23 623 8", "6 6 8956 56895 41", "", "15557 15 1 1 1556"] $aNewArray = StringSplit(StringRegExpReplace(_ArrayToString($aArray), "\b(\h+|\d{1,4})\b", ""), "|", 3) _ArrayDisplay($aNewArray, "", Default, 8) Link to comment Share on other sites More sharing options...
markyrocks Posted October 15, 2021 Share Posted October 15, 2021 for funzies... Idk why the non capturing group wasn't working. then i looked at the documentation to see it was actually in there then came back and it was working.... weird like im being spied on.... #include <Array.au3> Global $aArray[] = ["112 56985 1 589 6", "15896 25 25 3636","", "6 6 8956 56895 4"] for $i in $aArray $ticket = StringRegExp($i, "^(?:.*\W*)(\d{5})(?:.*)$|(^$)", 1) if IsArray($ticket) Then _ArrayDisplay($ticket) Next Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Felicitas Posted October 15, 2021 Author Share Posted October 15, 2021 Thank you so much. I will try the solutions asap. I love this forum. Very kind helpers everywhere 😘 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