Sign in to follow this  
Followers 0
water

Strange behaviour of StringStripWS

5 posts in this topic

#1 ·  Posted (edited)

StringStripWs($sString, 7) removes @CRLF at the start and end of a string but replaces it with @LF in the middle of a string.

Is this desired behaviour?

Example:

$sStringIn = @CRLF & "---" & @CRLF & "---" & @CRLF
$sStringOut = StringStripWS($sStringIn, 7)
; To enhance readability @CR is replaced with "@CR" and @LF with "@LF"
$sStringInDisplay = StringReplace($sStringIn, @CR, "@CR")
$sStringInDisplay = StringReplace($sStringInDisplay, @LF, "@LF")
$sStringOutDisplay = StringReplace($sStringOut, @CR, "@CR")
$sStringOutDisplay = StringReplace($sStringOutDisplay, @LF, "@LF")
MsgBox(0, "Result", "$sStringIn: " & $sStringInDisplay &  ", length: " & StringLen($sStringIn) & @CRLF & _
"$sStringOut: " & $sStringOutDisplay &  ", length: " & StringLen($sStringOut))
Tested with 3.3.8.1 and 3.3.9.23. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites



the behavior you demonstrate is due to the fact that both the @CR and @LF characters are seen as a "whitespace" character and you have selected option 4 to strip double whitespace character.

This demonstrates the behaviour where you can even see in the last case the SPACE remains:

$sStringIn = @CRLF & "-1-" & @CRLF & "-2-" & @CR & "-3-" & @LF & "-4-"  & @CR & @CR & "-5-" & @LF & @LF & "-6-" & " " & @LF & "-7-" & @CRLF
$sStringOut = StringStripWS($sStringIn, 7)
; To enhance readability @CR is replaced with "@CR" and @LF with "@LF"
$sStringInDisplay = StringReplace($sStringIn, @CR, "@CR")
$sStringInDisplay = StringReplace($sStringInDisplay, @LF, "@LF")
$sStringOutDisplay = StringReplace($sStringOut, @CR, "@CR")
$sStringOutDisplay = StringReplace($sStringOutDisplay, @LF, "@LF")
ConsoleWrite("$sStringIn: " & $sStringInDisplay &  ", length: " & StringLen($sStringIn) & @CRLF & "$sStringOut: " & $sStringOutDisplay &  ", length: " & StringLen($sStringOut)& @CRLF)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ah, I see :)

Flag 4 strips double (or more) whitespace characters between words. That's why one whitespace character remains in the middle of the string.

Flag 3 strips leading and trailing whitespace characters.

Thanks for the clarification!

I should have had another coffee before asking ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I understand why it does removes the "double" whitespace character, but even though it's technically correct that @CRLF is a "double" whitespace character, I can't believe that even though it's working as programmed, it's working as intended. A minor issue that's easily gotten around, to be sure, but it certainly seems strange that autoit (which is written for windows) would include a function that changes the "new line" characters to a Unix/Mac standard. Just throwing in my two cents.

Share this post


Link to post
Share on other sites

Agree that it could lead to confusion as it did with Water.

My reply was merely explaining why it happened, but would agree that most would expect option 4 to process only horizontal white-space characters (SPACES & TABS).

Jos :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0