Function Reference


Strips the white space in a string.

StringStripWS ( "string", flag )


string The string to strip.
flag Flag to indicate the type of stripping that should be performed (add the flags together for multiple operations):
    $STR_STRIPLEADING (1) = strip leading white space
    $STR_STRIPTRAILING (2) = strip trailing white space
    $STR_STRIPSPACES (4) = strip double (or more) spaces between words
    $STR_STRIPALL (8) = strip all spaces (over-rides all other flags)

Constants are defined in StringConstants.au3.

Return Value

Returns the new string stripped of the requested white space.


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

To strip single spaces between words, use the function StringReplace().


StringIsSpace, StringReplace, StringStripCR


#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

; Strip leading and trailing whitespace as well as the double spaces (or more) in between the words.
Local $sString = StringStripWS("   This   is   a   sentence   with   whitespace.    ", $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)
MsgBox($MB_SYSTEMMODAL, "", $sString)