Shanheavel Posted November 27, 2011 Share Posted November 27, 2011 (edited) Hello, I've string: [D: D, D] A Dwhere D is digital (0-9), A is some alpha (A-Z) string and D appears as digital or doesn't appear. So example string can be: [126: 1, 99] Hello!or [1921: 34, 50] Text 501 How can I get these values to array, e.g. $Array = [1921, 34, 50, "Text", 501] ? Edited November 27, 2011 by Shanheavel Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2011 Moderators Share Posted November 27, 2011 Shanheavel, This looks as if it might do what you want: #include <Array.au3> $sString = "[126: 1, 99] Hello!" $aRet = StringRegExp($sString, "w+", 3) _ArrayDisplay($aRet) $sString = "[1921: 34, 50] Text 501" $aRet = StringRegExp($sString, "w+", 3) _ArrayDisplay($aRet) 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...
jchd Posted November 27, 2011 Share Posted November 27, 2011 Let me suggest something else: #include <Array.au3> Local $text[2] = [ _ "[1921: 34, 50] Text 501", _ "[1921: 34, 50] Hello!" _ ] Local $Array[5], $res, $sep = Chr(0x01) For $i = 0 To UBound($text) - 1 ;~ Local $Array[5] = Execute(StringRegExpReplace($text[$i], "[(d+):s*(d+),s*(d+)]s*(S+)s*(d+)?", "[Int($1), Int($2), Int($3), '$4', Int('$5')]")) $res = StringSplit(StringRegExpReplace($text[$i], "[(d+):s*(d+),s*(d+)]s*(S+)s*(d+)?", "Int($1)"&$sep&"Int($2)"&$sep&"Int($3)"&$sep&"'$4'"&$sep&"Int('$5')"), $sep, 2) For $j = 0 To UBound($res) - 1 $Array[$j] = Execute($res[$j]) Next _ArrayDisplay($Array) Next Elements type should be fine and ponctuation characters are allowed in the text part. Could be adjusted if the text part may in fact be a phrase but please specify which characters might be there. I tried variations using Assign and Execute but it doesn't seem possible to assign an array in one shot by these means. I won't submit a feature request for allowing that, as it doesn't look like it would be widely used, if ever. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2011 Moderators Share Posted November 27, 2011 jchd,I did wonder about the missing "!" in my solution, but the OP did say:"A is some alpha (A-Z) string"so I decided that it was not required - and it made the SRE much simpler! 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...
jchd Posted November 27, 2011 Share Posted November 27, 2011 I get it but you know how to treat such rules: wait for exceptional cases found in practice. But if you look closer, having to later apply Number() to every numeric entry in the array doesn't make the whole process really much simpler. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
UEZ Posted November 27, 2011 Share Posted November 27, 2011 A non RegEx method: #include <Array.au3> $string1 = "[126: 1, 99] Hello!" $string2 = "[1921: 34, 50] Text 501" $aSplit = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace($string1, "[", ""), "]", ""), ":", ""), ",", ""), " ", 2) _ArrayDisplay($aSplit) $aSplit = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace($string2, "[", ""), "]", ""), ":", ""), ",", ""), " ", 2) _ArrayDisplay($aSplit) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Shanheavel Posted November 27, 2011 Author Share Posted November 27, 2011 Thank you all for help! @UEZ I used something like it. 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