compact21 Posted January 17, 2016 Share Posted January 17, 2016 Example() Func Example() Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri.Sat,Sun", ",.") ; Split the string of days using the delimiter "," and the default flag value. For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i]) Next EndFunc ;==>Example Hello, this is from help file. How do i return all values excluding "Fri" which is delimited by a period? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2016 Moderators Share Posted January 17, 2016 compact21, You need a RegEx for that: #include <Array.au3> #include <StringConstants.au3> $sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun" Example() _NoPeriod() Func Example() Local $aDays = StringSplit($sText, ",.") ; Split the string of days using the delimiter "," and the default flag value. _ArrayDisplay($aDays, "StringSplit", Default, 8) EndFunc ;==>Example Func _NoPeriod() $aDays = StringRegExp($sText, "(\w{3,4})(?:,|\z)", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aDays, "RegEx", Default, 8) EndFunc RegEx decode: (\w{3,4}) - capture all sequences of 3 or 4 letters (?:,|\z) - followed by a comma or the end of the string, but do not capture this delimiter 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 January 17, 2016 Share Posted January 17, 2016 A variation #Include <Array.au3> Local $sDays = "Mon,Tues,Wed,Thur,Fri.Sat,Sun" Local $aDays = StringRegExp($sDays, '\w+(?=,|$)', 3) _ArrayDisplay($aDays) This one means : "get all sequences of word chars followed by a comma or end of string" Link to comment Share on other sites More sharing options...
czardas Posted January 17, 2016 Share Posted January 17, 2016 Ha, Melba and mikell beat me to it. I remove the unwanted day using StringRegExpReplace() before using StringSplit(). The regular expression is different: removing anything ending with a period. It serves as another illustration of the numerous possible ways there are to do things. Example() Func Example() Local $sString = StringRegExpReplace("Mon,Tues,Wed,Thur,Fri.Sat,Sun", '[^,]+\.', '') ; remove xxxx. Local $aDays = StringSplit($sString, ",") ; Split the string of days using the delimiter "," and the default flag value. For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i]) Next EndFunc ;==>Example operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
iamtheky Posted January 17, 2016 Share Posted January 17, 2016 Or if you have already determined what the string is that needs to be removed, just split on it in its entirety #include<array.au3> $sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun" $aText = stringsplit($sText , "Fri." , 3) msgbox(0, '' , _ArrayToString($aText , "")) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
compact21 Posted January 17, 2016 Author Share Posted January 17, 2016 (edited) Thank you M23. Exactly what i needed. Edited January 17, 2016 by compact21 Link to comment Share on other sites More sharing options...
compact21 Posted January 17, 2016 Author Share Posted January 17, 2016 53 minutes ago, Melba23 said: compact21, You need a RegEx for that: #include <Array.au3> #include <StringConstants.au3> $sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun" Example() _NoPeriod() Func Example() Local $aDays = StringSplit($sText, ",.") ; Split the string of days using the delimiter "," and the default flag value. _ArrayDisplay($aDays, "StringSplit", Default, 8) EndFunc ;==>Example Func _NoPeriod() $aDays = StringRegExp($sText, "(\w{3,4})(?:,|\z)", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aDays, "RegEx", Default, 8) EndFunc RegEx decode: (\w{3,4}) - capture all sequences of 3 or 4 letters (?:,|\z) - followed by a comma or the end of the string, but do not capture this delimiter M23 A tip how to use StringRegExp when delimiter is "?" instead of "," ? Thakn you. Link to comment Share on other sites More sharing options...
mikell Posted January 17, 2016 Share Posted January 17, 2016 Just escape the question mark with a backslash => \? Link to comment Share on other sites More sharing options...
iamtheky Posted January 17, 2016 Share Posted January 17, 2016 #include<array.au3> $delim = "?" ;~ $sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun" $sText = "Mon,Tues,Wed?Thur,Fri,Sat,Sun" $aText = stringsplit(stringreverse(stringregexpreplace(stringreverse($sText) , "(\" & $delim & "\D+?)," , ",")) , "," , 2) _ArrayDisplay($aText) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted January 17, 2016 Share Posted January 17, 2016 #Include <Array.au3> $delim = "?" Local $sDays = "Mon?Tues?Wed?Thur?Fri.Sat?Sun" Local $aDays = StringRegExp($sDays, '\w+(?=\Q' & $delim & '\E|$)', 3) _ArrayDisplay($aDays) iamtheky 1 Link to comment Share on other sites More sharing options...
iamtheky Posted January 17, 2016 Share Posted January 17, 2016 (edited) yup I was backwards, I totally thought he asked what if it was '?' instead of '.' \Q....\E would make my regex life so much easier if I remembered to use them, but working on the reversed string is still my favorite way to provide examples Edited January 17, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted January 17, 2016 Share Posted January 17, 2016 1 hour ago, iamtheky said: .. working on the reversed string is still my favorite way to provide examples I admit that this could be efficient but isn't it a slightly twisted way ? Link to comment Share on other sites More sharing options...
iamtheky Posted January 17, 2016 Share Posted January 17, 2016 but its an easy win for the recipient to fix and then they have to reverse the regex which means they did something more than copy/paste. And if you see that crap from anyone but me, you know where they got it from. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted January 17, 2016 Share Posted January 17, 2016 Irrefutable argument ... hat off Link to comment Share on other sites More sharing options...
compact21 Posted January 18, 2016 Author Share Posted January 18, 2016 Thanks a lot! 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