Core Function StripWS
StripWS( <str>, <flags>, <charList> )
Contents |
Description
Strips the white space in a string or given characters.
Parameters
str
The string to strip.
flags
Flag to indicate the type of stripping that should be performed (add the flags together for multiple operations):
1 = strip leading white space
2 = strip trailing white space
4 = strip double (or more) spaces between words
8 = strip all spaces (over-rides all other flags)
So if you wanted to strip leading and trailing whitespace only you would enter the flag 1 | 2
To strip every double space AND remove the trailing (but not the leading) you would do 2 | 4
charList
Optional; A string to use its characters as the character list used when splitting.
By default the charList is the usual whitespace characters (see remarks) however if you set your own here you can be specific on what you want to call whitespace.
For example if the charList is "-#" then - and # will be classed as whitespace and ONLY they will be classed as whitespace nothing else.
Default: "\t\n\v\r\s\0"
Return Value
Returns the new string stripped of the requested white space.
Remarks
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) ).
Example
echo( "'" . StripWS(" Hello World ", 1) . "'\n" ); // 'Hello World ' echo( "'" . StripWS(" Hello World ", 2) . "'\n" ); // ' Hello World' echo( "'" . StripWS(" Hello World ", 1 | 2) . "'\n" ); // 'Hello World' echo( "'" . StripWS(" Hello World ", 4) . "'\n" ); // ' Hello World ' echo( "'" . StripWS(" Hello World ", 8) . "'\n" ); // 'HelloWorld'
Custom charList
echo( "'" . StripWS("-----Hello---World-------", 1 | 2 | 4, "-") . "'\n" ); // 'Hello-World' echo( "'" . StripWS("-----Hello---World-------", 1 | 2, "-") . "'\n" ); // 'Hello---World' echo( "'" . StripWS("-----Hello---World-------", 8, "-") . "'\n" ); // 'Helloorld'