mohamad Posted October 17, 2014 Share Posted October 17, 2014 (edited) Hello guys, i want to split $sText and get the same results as displayed except "hardalot"(hard alot),i want them to be seperate but in the same time i want sug-gestion to be combined. #include <array.au3> Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" MsgBox(0,"",$sText) Local $aArray = StringSplit($sText, ' ') _ArrayDisplay($aArray) Edited October 17, 2014 by mohamad Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 17, 2014 Moderators Solution Share Posted October 17, 2014 Mohamed,How about this: #include <Array.au3> Local $sText = "Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" $sText = StringReplace(StringReplace($sText, "-" & @CRLF, ""), @CRLF, " ") Local $aArray = StringSplit($sText, " ") _ArrayDisplay($aArray)M23 mohamad 1 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...
mohamad Posted October 17, 2014 Author Share Posted October 17, 2014 works great Link to comment Share on other sites More sharing options...
czardas Posted October 17, 2014 Share Posted October 17, 2014 (edited) Oh, I wrote something a little more complicated. It checks that the hyphen dash is part of a split word, or not, before joining. It also ignores multiple spaces and line breaks. ; Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" Local $aArray = StringRegExp(StringRegExpReplace($sText, "(?i)(?<=[a-z])\-\r\n(?=[a-z])", ""), "\S+", 3) _ArrayDisplay($aArray) :; Or with the item count added. Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" Local $aArray = StringRegExp(StringRegExpReplace("? " & $sText, "(?i)(?<=[a-z])\-\r\n(?=[a-z])", ""), "\S+", 3) $aArray[0] = UBound($aArray) -1 _ArrayDisplay($aArray) ; It's the same approach as Melba23, but a little more fussy. Edited October 17, 2014 by czardas mohamad 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mohamad Posted October 17, 2014 Author Share Posted October 17, 2014 Oh, I wrote something a little more complicated. It checks that the hyphen dash is part of a split word, or not, before joining. It also ignores multiple spaces and line breaks. ; Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" Local $aArray = StringRegExp(StringRegExpReplace($sText, "(?i)(?<=[a-z])\-\r\n(?=[a-z])", ""), "\S+", 3) _ArrayDisplay($aArray) :; Or with the item count added. Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" Local $aArray = StringRegExp(StringRegExpReplace("? " & $sText, "(?i)(?<=[a-z])\-\r\n(?=[a-z])", ""), "\S+", 3) $aArray[0] = UBound($aArray) -1 _ArrayDisplay($aArray) ; It's the same approach as Melba23, but a little more fussy. That's amazing ,i never thought such thing could be possible. this helped me alot,thanks! czardas 1 Link to comment Share on other sites More sharing options...
czardas Posted October 17, 2014 Share Posted October 17, 2014 (edited) I'm glad you liked that version. AutoIt is so rich with methods and I'm often surprised by things myself. Simple solutions are usually the best and also fundamental to learning. Sometimes there are many factors to consider and a more complicated solution is required. The code I posted is not able to differentiate between a genuine word split and a hyphenated word interrupted by a line break. There is no general solution for that, as far as I know. Edited October 17, 2014 by czardas mohamad 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted October 17, 2014 Share Posted October 17, 2014 (edited) For the fun #Include <Array.au3> Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" $aArray = StringSplit(StringRegExpReplace(StringRegExpReplace($sText, '\R|-(?=\w)', " "), '-\h+', ""), ',') _ArrayDisplay($aArray) Edited October 17, 2014 by mikell mohamad 1 Link to comment Share on other sites More sharing options...
czardas Posted October 17, 2014 Share Posted October 17, 2014 I like the part about eating an apple. mohamad 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted October 17, 2014 Share Posted October 17, 2014 Right. For the fun AND for the apple mohamad and czardas 2 Link to comment Share on other sites More sharing options...
mohamad Posted October 17, 2014 Author Share Posted October 17, 2014 (edited) For the fun #Include <Array.au3> Local $sText="Test text- - ,do-what-ever-you-want ,eat-apple ,write sug-" & @CRLF & "gestion and work hard" & @CRLF & "alot" $aArray = StringSplit(StringRegExpReplace(StringRegExpReplace($sText, '\R|-(?=\w)', " "), '-\h+', ""), ',') _ArrayDisplay($aArray) ... i probably should read more about StringRegExpReplace,used to use a long code to remove "-" between words , thanks , this meant more than fun to me . Edited October 17, 2014 by mohamad 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