Search the Community
Showing results for tags 'stringstripws'.
-
Question : The StringStripWS function contains the statement, Flag : $STR_STRIPALL (8) = strip all spaces (over-rides all other flags) In the German forum @Professor_Bernd wrote me, that this is an incorrect description. A test we made revealed, that it seems to be exactly the other way around. $STR_STRIPALL gets overwritten by all other flags. Example : #include <StringConstants.au3> Local $sOriginal = " A sentence with whitespace. " , $sOutput ConsoleWrite(" -------------------------------------------------------------------------------------" & @CRLF) ConsoleWrite("+ Original : <" & $sOriginal & ">" & @CRLF) ConsoleWrite(" -------------------------------------------------------------------------------------" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPLEADING) & ">") ConsoleWrite("> >>>>>>> 1. <" & $sOutput & "==> STRIPLEADING" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPTRAILING) & ">") ConsoleWrite("> >>>>>>> 2. <" & $sOutput & "==> STRIPTRAILING" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPSPACES) & ">") ConsoleWrite("> >>>>>>> 3. <" & $sOutput & "==> STRIPSPACES" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) & ">") ConsoleWrite("> >>>>>>> 4. <" & $sOutput & "==> STRIPLEADING + STRIPTRAILING + STRIPSPACES" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPALL) & ">") ConsoleWrite("> >>>>>>> 5. <" & $sOutput & "==> STRIPALL" & @CRLF) ConsoleWrite(" -------------------------------------------------------------------------------------" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPALL + $STR_STRIPLEADING) & ">") ConsoleWrite("! >>>>>>> 6. <" & $sOutput & "==> STRIPALL + STRIPLEADING" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPALL + $STR_STRIPTRAILING) & ">") ConsoleWrite("! >>>>>>> 7. <" & $sOutput & "==> STRIPALL + STRIPTRAILING" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPALL + $STR_STRIPSPACES) & ">") ConsoleWrite("! >>>>>>> 8. <" & $sOutput & "==> STRIPALL + $STR_STRIPSPACES" & @CRLF) $sOutput = StringFormat("%-40s", StringStripWS($sOriginal, $STR_STRIPALL + $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) & ">") ConsoleWrite("! >>>>>>> 9. <" & $sOutput & "==> STRIPALL + STRIPLEADING + STRIPTRAILING + STRIPSPACES" & @CRLF) ConsoleWrite(" -------------------------------------------------------------------------------------" & @CRLF) Is this behavior already known, or have we possibly misunderstood something. Any clarification is welcome. TIA @Musashi and @Professor_Bernd
-
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 : 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.
- 9 replies
-
- stringstripws
- @cr
-
(and 2 more)
Tagged with:
-
Small chance i'm too tired to think straight, but I do believe this is a bug. I was reading strings from a file which were 32 bytes in length. Padded with 00's So I thought i'd strip off the exess with StringStripWS. Which docs say can strip CHR(0) as whitespace. Not working, here's a modified from the Example that Duplicates the problem. All whitespace removed exept the Null Char. #include <StringConstants.au3> #include <MsgBoxConstants.au3> ; Strip leading and trailing whitespace as well as the double spaces (or more) in between the words. Local $sString = "Thisisasentencewithwhitespace." & CHR(0) ConsoleWrite(StringLen($sString) & @CRLF) $sString = StringStripWS($sString, $STR_STRIPTRAILING) ConsoleWrite(StringLen($sString) & @CRLF) Prints to console size of the string before and after as 31. No Changes.