dersiniar Posted June 29, 2022 Share Posted June 29, 2022 I have $txt string that is changing " July 20 - August 16"How i can get only part "August 16" I cant use StringInStr($txt,"-") Cos $txt returns values like those " July 2 - 4" as well Some samples of $txt output: July 3 July 7 July 5 - 9 * July 2 - 4 July 20 - August 16 July 5 - 9 July 4 - 6 July 6 - 12 July 5 - 8 July 6 - 14 July 20 - September 16** July 6 - 12 And i need to get Latest month and i need latest day, and i need to but them together. Example September 16 ** and July 9 * I know how to use StringLeft, mid, right etc, I juyst dont understand how to get Latest month out of string. Latest number i can just do StringRight($txt,2) Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted June 29, 2022 Moderators Solution Share Posted June 29, 2022 dersiniar, This seems to work: #include <Array.au3> #include <StringConstants.au3> $sString = "July 3" & @CRLF & _ "July 7" & @CRLF & _ "July 5 - 9 *" & @CRLF & _ "July 2 - 4" & @CRLF & _ "July 20 - August 16" & @CRLF & _ "July 5 - 9" & @CRLF & _ "July 4 - 6" & @CRLF & _ "July 6 - 12" & @CRLF & _ "July 5 - 8" & @CRLF & _ "July 6 - 14" & @CRLF & _ "July 20 - September 16**" & @CRLF & _ "July 6 - 12" $aArray = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT) ;_ArrayDisplay($aArray, "", Default, 8) For $i = 1 To $aArray[0] ; Look for the sequence "- Any capital letter" If StringRegExp($aArray[$i], "\-\s[A-Z]") Then ; If found then remove everythign before the capital letter $aArray[$i] = StringRegExpReplace($aArray[$i], "^.*\-\s(.*)$", "$1") EndIf Next _ArrayDisplay($aArray, "", 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...
Developers Jos Posted June 29, 2022 Developers Share Posted June 29, 2022 This is the one I came up with: Global $test = ["July 5 - 9", "July 2 - 4", "July 20 - August 16"] For $x = 0 To UBound($test) - 1 $test[$x] = StringRegExpReplace($test[$x], "[^\-]*\-\s*([A-Z]+)", "$1") Next _ArrayDisplay($test) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Subz Posted June 29, 2022 Share Posted June 29, 2022 This worked for me. #include <Array.au3> Local $sString = "July 3" & @CRLF & _ "July 7" & @CRLF & _ "July 5 - 9 *" & @CRLF & _ "July 2 - 4" & @CRLF & _ "July 20 - August 16" & @CRLF & _ "July 5 - 9" & @CRLF & _ "July 4 - 6" & @CRLF & _ "July 6 - 12" & @CRLF & _ "July 5 - 8" & @CRLF & _ "July 6 - 14" & @CRLF & _ "July 20 - September 16**" & @CRLF & _ "July 6 - 12" Local $aString = StringRegExp($sString, "(?:.*-\s)([A-Za-z]*\s[0-9]*)", 3) _ArrayDisplay($aString) Link to comment Share on other sites More sharing options...
dersiniar Posted June 29, 2022 Author Share Posted June 29, 2022 18 minutes ago, Jos said: This is the one I came up with: Global $test = ["July 5 - 9", "July 2 - 4", "July 20 - August 16"] For $x = 0 To UBound($test) - 1 $test[$x] = StringRegExpReplace($test[$x], "[^\-]*\-\s*([A-Z]+)", "$1") Next _ArrayDisplay($test) I like your code, looks like it works. But can you explain little how it picks up this and how i can use it for variable? If i use MsgBox(0,"",$test) i get 0 output Link to comment Share on other sites More sharing options...
Developers Jos Posted June 29, 2022 Developers Share Posted June 29, 2022 3 minutes ago, dersiniar said: $test This is an Array not a regular variable, so requires [] at the end. Obviously you can use a regular variable as well with the StringRegexReplace() line. dersiniar 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dersiniar Posted June 29, 2022 Author Share Posted June 29, 2022 42 minutes ago, Melba23 said: dersiniar, This seems to work: #include <Array.au3> #include <StringConstants.au3> $sString = "July 3" & @CRLF & _ "July 7" & @CRLF & _ "July 5 - 9 *" & @CRLF & _ "July 2 - 4" & @CRLF & _ "July 20 - August 16" & @CRLF & _ "July 5 - 9" & @CRLF & _ "July 4 - 6" & @CRLF & _ "July 6 - 12" & @CRLF & _ "July 5 - 8" & @CRLF & _ "July 6 - 14" & @CRLF & _ "July 20 - September 16**" & @CRLF & _ "July 6 - 12" $aArray = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT) ;_ArrayDisplay($aArray, "", Default, 8) For $i = 1 To $aArray[0] ; Look for the sequence "- Any capital letter" If StringRegExp($aArray[$i], "\-\s[A-Z]") Then ; If found then remove everythign before the capital letter $aArray[$i] = StringRegExpReplace($aArray[$i], "^.*\-\s(.*)$", "$1") EndIf Next _ArrayDisplay($aArray, "", Default, 8) M23 Thank you, i used your code, and i got it work. ❤️ Thanks 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