Jump to content
Sign in to follow this  
water

Strange behaviour of StringStripWS

Recommended Posts

water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jos

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


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
FlashpointBlack

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
Jos

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 :)


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        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  

×