Jump to content

StringStripWS - @CR still there - (Moved)


Jeep
 Share

Recommended Posts

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 by Melba23
Added tags
Link to comment
Share on other sites

  • Moderators

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 by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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 by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

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

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...