v5.0
JScript and other languages offer sophisticated string
manipulation functions via regular expressions. However regular
expressions can be a little daunting to learn. This command
provides a simple solution for the common task of triming extra
space characters from from the front or end of a string. To write a
truly user-friend interface it is prudent to always clean input
strings in this fashion.
Note: This function does not remove any tab characters (\t) or
linefeeds (\n) from the string.
oString = TrimString( StringToTrim, [TrimLeft], [TrimRight] ); |
Parameter | Type | Description |
---|---|---|
StringToTrim | String | Input that might contain extra white space characters |
TrimLeft | Boolean | whether to remove all leading white space
Default Value: true |
TrimRight | Boolean | whether to remove all trailing white space
Default Value: true |
cleanedString = TrimString( " myname " ) ; // cleanedString will contain "myname" Application.LogMessage(cleanedString); |
/* Demonstration of how JScript's regular expression functionality can be used instead of the TrimString command */ Application.LogMessage( TrimSpaces( " myname " ) ) ; function TrimSpaces( in_str ) { // Strip front and back spaces // (also cleans out \t and \n characters) return in_str.replace(/(^\s*)|(\s*$)/g, ""); } |