Jump to content

Strange behaviour of StringStripWS


water
 Share

Recommended Posts

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...