Seminko Posted January 6, 2015 Share Posted January 6, 2015 Hey fellas, I have these text strings in an array: Customer Details 1 Site Details 2 Slough Primary 2 Slough Secondary 5 Dynamic Bandwidth 9 Billing Details 14 How do I remove the last space and number so I have this: Customer Details Site Details Slough Primary Slough Secondary Dynamic Bandwidth Billing Details Please note the in this example we have only two words in the strings but it can easily be more ie: "Slough UK based Primary" etc. Also, the numbers can be either one, two or even three digits long. Thank you! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2015 Moderators Share Posted January 6, 2015 Seminko,This seems to do the trick:#include <Array.au3> Global $aArray[] = ["Customer Details 1", "Site Details 2", "Slough Primary 2", "Slough Secondary 5", "Dynamic Bandwidth 9", "Billing Details 14"] For $i = 0 To UBound($aArray) - 1 $aArray[$i] = StringRegExpReplace($aArray[$i], "\s(\d+)", "") Next _ArrayDisplay($aArray, "", Default, 8)Basically remove anything that matches "space followed by at least 1 digit until the next non-digit". 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...
kylomas Posted January 6, 2015 Share Posted January 6, 2015 Another take on it, allows numbers in the text... #include <array.au3> Local $aBefore = [ _ 'Customer9 Details3 1', _ 'Site 14 Details 2', _ 'Slough Primary 2', _ 'Slough Secondary 5', _ '14Dynamic Bandwidth 9', _ 'Billing Details 14' _ ] For $1 = 0 To UBound($aBefore) - 1 $aBefore[$1] = StringRegExpReplace($aBefore[$1], '([\w+]) \d+$', '\1') Next _ArrayDisplay($aBefore) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Seminko Posted January 6, 2015 Author Share Posted January 6, 2015 (edited) Hey Melba, thanks! Well that got me thinking because there MIGHT be a case where there is a number in the title, say something like: "Customer 1 Details 9" and I would like for it to return: "Customer 1 Details" It might help that before I StringSplit the string into an array there were line breaks (I used @CRLF as a delimiter) just like you see in my example. So let's say this is how the string returned by ClipGet looks like: Customer Details 1 Site Details 2 Slough Primary 2 Slough Secondary 5 Dynamic Bandwidth 9 Billing Details 14 Could we do sth like: look for a space followed by at least 1 digit until line break (@CRLF)? Thanks Edited January 6, 2015 by Seminko Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2015 Moderators Share Posted January 6, 2015 (edited) kylomas,Well, if you want to be fussy: #include <Array.au3> Global $aArray[] = ["Customer Details 1", "Site Details 2", "Slough 14 Primary 2", "Slough Secondary 5", "Dynamic Bandwidth 9", "Billing Details 14"] For $i = 0 To UBound($aArray) - 1 $aArray[$i] = StringRegExpReplace($aArray[$i], "^(.*)\s\d+$", "$1") Next _ArrayDisplay($aArray, "", Default, 8)M23Edit:Seminko,Looks like we were there ahead of you! Edited January 6, 2015 by Melba23 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...
kylomas Posted January 6, 2015 Share Posted January 6, 2015 Yes, any other changes? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted January 6, 2015 Share Posted January 6, 2015 I have got to find a smiley of a guy pissing out of an airplane... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Seminko Posted January 6, 2015 Author Share Posted January 6, 2015 Another take on it, allows numbers in the text... #include <array.au3> Local $aBefore = [ _ 'Customer9 Details3 1', _ 'Site 14 Details 2', _ 'Slough Primary 2', _ 'Slough Secondary 5', _ '14Dynamic Bandwidth 9', _ 'Billing Details 14' _ ] For $1 = 0 To UBound($aBefore) - 1 $aBefore[$1] = StringRegExpReplace($aBefore[$1], '([\w+]) \d+$', '\1') Next _ArrayDisplay($aBefore) kylomas Exactly what I needed. Thanks both of you guys for such a swift response! I can move on now Link to comment Share on other sites More sharing options...
Solution kylomas Posted January 6, 2015 Solution Share Posted January 6, 2015 Use this one. It allows for any number of spaces between the text you want and the numbers... #include <array.au3> Local $aBefore = [ _ 'Customer9 Details3 1', _ 'Site 14 Details 2', _ 'Slough Primary 2', _ 'Slough Secondary 5', _ '14Dynamic Bandwidth 9', _ 'Billing Details 14' _ ] For $1 = 0 To UBound($aBefore) - 1 $aBefore[$1] = StringRegExpReplace($aBefore[$1], '([\w+])\s+\d+$', '\1') Next _ArrayDisplay($aBefore) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
willichan Posted January 6, 2015 Share Posted January 6, 2015 I have got to find a smiley of a guy pissing out of an airplane... Its not from an airplane, but this might work. '> My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
kylomas Posted January 6, 2015 Share Posted January 6, 2015 (edited) @willichan Thanks but it does not have a M23 feel to it... Edited January 6, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jguinch Posted January 6, 2015 Share Posted January 6, 2015 Shorter : StringRegExpReplace($aArray[$i], "\s\d+$", "") Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2015 Moderators Share Posted January 6, 2015 kylomas,I rather hope "a guy pissing out of an airplane" does not have "a M23 feel to it" either! 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...
kylomas Posted January 6, 2015 Share Posted January 6, 2015 @M23 - Of course not!! Something more along the lines of the 'Red Baron'... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted January 6, 2015 Share Posted January 6, 2015 kylomas, ([w+]) seems to make no sense, as there is no "+" in the strings and this matches any word char in the string (except in the part to be deleted) Link to comment Share on other sites More sharing options...
kylomas Posted January 7, 2015 Share Posted January 7, 2015 (edited) @mikell, yes, you're right, thank you... edit: I like jguinch's solution... #include <array.au3> Local $aBefore = [ _ 'Customer9 Details3 1', _ 'Site 14 Details 2', _ 'Slough Primary 2', _ 'Slough Secondary 12 5', _ '14Dynamic Bandwidth 9', _ 'Billing Details 14' _ ] For $1 = 0 To UBound($aBefore) - 1 $aBefore[$1] = StringRegExpReplace($aBefore[$1], '\s\d+$', '') Next _ArrayDisplay($aBefore) Edited January 7, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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