Jump to content

Recommended Posts

Posted (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) ).
"

Expand  

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
  • Moderators
Posted (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 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:

  Reveal hidden contents

 

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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

 

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted
  On 1/26/2019 at 1:33 PM, Chimp said:

(leaving just only one in place of the 2 or more whitespaces)

Expand  

I'd rather say : it leaves the first one and fires the others

  On 1/26/2019 at 1:33 PM, Chimp said:

It consider @cr @lf.. and all the other "white spaces" as if that are normal spaces chr(32)

Expand  

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

Posted

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 

  • Moderators
Posted

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:

  Reveal hidden contents

 

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
×
×
  • Create New...