Jeep Posted January 26, 2019 Share Posted January 26, 2019 (edited) Hello, I'm comming from the french site "Autoitsript.fr" with the following question or problem. I try to use StringStripWS to clean spaces and control characters in a string. Here is my code. #include <String.au3> #include <StringConstants.au3> #include <Array.au3> ;---- Part 1 Local $sText = @TAB & "This is a new story." & @CR & @LF & "Once upon a time ... " Local $sCheck = "" $sCheck = StringStripWS($sText, BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING, $STR_STRIPSPACES)) ;$sCheck = StringStripWS($sText, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) ConsoleWrite($sCheck & @CRLF) For $i = 1 to stringlen($sCheck) ConsoleWrite(stringmid($sCheck,$i,1) & "-" & Asc(stringmid($sCheck,$i,1)) & @CRLF) next ; Part 2 --- Workarround submited by "jchd" on he french site Local $sText = @TAB & " This is a new story." & @CR & @LF & "Once upon a time ... " Local $sCheck = StringStripWS(StringRegExpReplace($sText, "[[:space:]]+", " "), $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) ConsoleWrite(">" & $sCheck & "<" & @LF) _ArrayDisplay(StringToASCIIArray($sCheck)) The help file tells : Quote "Remarks Whitespace includes Chr(9) thru Chr(13) which are HorizontalTab, LineFeed, VerticalTab, FormFeed, and CarriageReturn. Whitespace also includes the null string ( Chr(0) ) and the standard space ( Chr(32) )." But if we check the console after program execution , the CarriageReturn (Chr(13) is still there. This is a mistake of the program, a bug or a feature of StringStripWS or a mistake in the help file. I use AutoIt v3.3.14.5. We have already a workaround (Part 2). Thanks in advance for your replies. Edited January 26, 2019 by Melba23 Added tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 26, 2019 Moderators Share Posted January 26, 2019 (edited) Jeep, Bienvenu au forum Anglophone! If I use StringStripWS($sText, $STR_STRIPALL) I get the Chr(13) characters removed from the string - which should solve your immediate problem. I will investigate further - but if jchd has to use a workaround it looks like there might well be a bug somewhere. M23 P.S. When you post code here please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation. Edit: No bug - see the works of others below. Edited January 27, 2019 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...
Moderators Melba23 Posted January 26, 2019 Moderators Share Posted January 26, 2019 Moved to the appropriate forum. Moderation Team 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 26, 2019 Share Posted January 26, 2019 IMHO it' not a bug. It rather seems that "whitespace" is used in a generic way ( Whitespace includes ... etc)$STR_STRIPSPACES (4) = strip double (or more) spaces between words , and in this example it's exactly what it does. This Local $sText = @TAB & "This is a new story. " & @CR & @LF & "Once upon a time ... " gives the expected result because of the space after the dot The workaround provided by jchd replaces a vertical WS by a horizontal one, while StringStripWS is not intended to do that Link to comment Share on other sites More sharing options...
Gianni Posted January 26, 2019 Share Posted January 26, 2019 (edited) StringstripWS, used with the $STR_STRIPSPACES (4) flag, strips double (or more) spaces between words (leaving just only one in place of the 2 or more whitespaces). Now, since @crlf are actually considered as 2 whitespaces, the function it leaves just one of them. So the single space (@cr) left by the function is correct. It consider @cr @lf.. and all the other "white spaces" as if that are normal spaces chr(32)... Edited January 26, 2019 by Chimp Jeep 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted January 26, 2019 Share Posted January 26, 2019 6 minutes ago, Chimp said: (leaving just only one in place of the 2 or more whitespaces) I'd rather say : it leaves the first one and fires the others 8 minutes ago, Chimp said: It consider @cr @lf.. and all the other "white spaces" as if that are normal spaces chr(32) I'd rather say : it doesn't care if spaces are horizontal or vertical OTOH In the code from jchd the SRER replaces one or more spaces (any) by one Chr(32) , reason why in this code $STR_STRIPSPACES is redundant Link to comment Share on other sites More sharing options...
Gianni Posted January 26, 2019 Share Posted January 26, 2019 21 minutes ago, mikell said: I'd rather say : .., I agree p.s. accuracy is not my specialty.... mikell 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted January 26, 2019 Share Posted January 26, 2019 My bad. I was not accurate enough too What I said in my 2nd post should have been mentioned in my first one Link to comment Share on other sites More sharing options...
Jeep Posted January 27, 2019 Author Share Posted January 27, 2019 Thanks everybody for your replies. Chimp, a special thanks. If I replace @CR @LF by @LF & @CR in my original string, now i found @LF in the result. If we replace multi spaces char by one, StringStripWS keep the first one. it's a normal behaviour of that function not a bug. Melba23, I promise to use "Code tags" the next time :-). There are not on the same place on the french site. Thanks for your welcome (merci pour votre "bienvenue"). Bye Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2019 Moderators Share Posted January 27, 2019 Chimp & mikell, I completely agree with your interpretation of the way in which the function works - my earlier post was in error. Thanks for the efforts to point me in the right direction! 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...
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